-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_normal_form.cpp
91 lines (72 loc) · 2.88 KB
/
test_normal_form.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "normal_form.hpp"
#include <gmock/gmock.h>
#include "lossless_decomposition.hpp"
const Field A = "A";
const Field B = "B";
const Field C = "C";
const Field D = "D";
const Field E = "E";
const Field F = "F";
const Field G = "G";
const Field H = "H";
const Field I = "I";
const Field J = "J";
static bool contains(const std::vector<FieldSet>& vec, const FieldSet& R) {
auto it = std::find(vec.begin(), vec.end(), R);
return it != vec.end();
}
TEST(normal_form, convert_3nf_non_lossless_decomposition) {
const auto fds = make_set(
make_FD(A, B),
make_FD(make_set(A, C, D), E),
make_FD(make_set(E, F), G));
const auto U = field_set_from(fds) + make_set(H);
ASSERT_EQ(U.size(), 8);
auto key = candidate_key(U, fds);
ASSERT_EQ(key, make_set(A, C, D, F, H));
std::vector<FieldSet> R_list = convert_3nf(U, fds);
ASSERT_TRUE(contains(R_list, make_set(A, C, D, F, H)));
}
TEST(normal_form, convert_3nf_when_non_lossless_decomposition_non_empty_remains) {
const auto fds = make_set(
make_FD(A, B),
make_FD(make_set(A, C, D), E),
make_FD(make_set(E, F), G));
const auto U = field_set_from(fds) + make_set(H);
std::vector<FieldSet> R_list = convert_3nf(U, fds);
ASSERT_EQ(R_list.size(), 4);
ASSERT_TRUE(contains(R_list, make_set(A, B)));
ASSERT_TRUE(contains(R_list, make_set(A, C, D, E)));
ASSERT_TRUE(contains(R_list, make_set(E, F, G)));
ASSERT_TRUE(contains(R_list, make_set(A, C, D, F, H)));
ASSERT_TRUE(is_lossless_decomposition(U, fds, R_list));
}
TEST(normal_form, convert_3nf_when_lossless_decomposition_empty_remains) {
const auto fds = make_set(
make_FD(A, B),
make_FD(make_set(A, C, D, F), E),
make_FD(make_set(E, F), G));
const auto U = field_set_from(fds);
ASSERT_EQ(fds, minimal_cover(fds));
ASSERT_EQ(candidate_key(U, fds), make_set(A, C, D, F));
std::vector<FieldSet> R_list = convert_3nf(U, fds);
ASSERT_EQ(R_list.size(), 3);
ASSERT_TRUE(contains(R_list, make_set(A, B)));
ASSERT_TRUE(contains(R_list, make_set(A, C, D, F, E)));
ASSERT_TRUE(contains(R_list, make_set(E, F, G)));
}
TEST(normal_form, convert_3nf_when_non_lossless_decomposition_empty_remains) {
const auto fds = make_set(
make_FD(A, B),
make_FD(make_set(A, C, D), E),
make_FD(make_set(E, F), G));
const auto U = field_set_from(fds);
ASSERT_EQ(fds, minimal_cover(fds));
std::vector<FieldSet> R_list = convert_3nf(U, fds);
ASSERT_EQ(make_set(A, C, D, F), candidate_key(U, fds));
ASSERT_EQ(R_list.size(), 4);
ASSERT_TRUE(contains(R_list, make_set(A, B)));
ASSERT_TRUE(contains(R_list, make_set(A, C, D, E)));
ASSERT_TRUE(contains(R_list, make_set(E, F, G)));
ASSERT_TRUE(contains(R_list, make_set(A, C, D, F)));
}