-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign_unittest.cpp
More file actions
149 lines (131 loc) · 3.78 KB
/
align_unittest.cpp
File metadata and controls
149 lines (131 loc) · 3.78 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2012 Florian Petran
#include<list>
#include<string>
#include<vector>
#include<map>
#include<gtest/gtest.h> // NOLINT[build/include_order]
#include"align.h"
#include"align_config.h"
#include"string_impl.h"
/*
* customer test
* test example alignment with two texts
* each phase has its own test, with the expected results
* hardcoded there.
* TODO make better example texts - the one used right now are
* real anselm texts.
*/
class AlignTest_Fixture : public testing::Test {
protected:
virtual void SetUp() {
Align::Params* params = Align::Params::get();
params->set_dict_base(ALIGN_TEST_DICT);
Align::DictionaryFactory* df =
Align::DictionaryFactory::get_instance();
_dict = df->get_dictionary(ALIGN_TEST_E, ALIGN_TEST_F);
c = new Align::Candidates(*_dict);
c->collect();
sc = new Align::AlignMake(c);
}
virtual void TearDown() {
delete c;
delete sc;
}
// data members
const Align::Dictionary* _dict;
Align::Candidates* c;
Align::AlignMake *sc;
};
class AlignTest : public AlignTest_Fixture {
};
TEST_F(AlignTest, CandidatesTest) {
std::map<int, std::list<int>> tr_exp =
{ { 8, {19, 30, 40} },
{ 9, {20, 35, 39} },
{ 10, {21, 9, 13} },
{ 12, {22, 27, 28} },
{ 13, {23, 28, 35} },
{ 17, {19, 30, 40} } };
std::map<int, std::list<int>> tr_actual;
for (auto act = c->begin(); act != c->end(); ++act)
for (auto act_tr = act->second->begin();
act_tr != act->second->end(); ++act_tr)
tr_actual[act->first.position()].push_back(act_tr->position());
EXPECT_EQ(tr_exp.size(), tr_actual.size());
EXPECT_EQ(tr_exp, tr_actual);
}
TEST_F(AlignTest, SequenceTestInital) {
sc->initial_sequences();
std::vector<std::vector<int>> expected_sequence = {
{ 8, 19,
9, 20 },
{ 10, 21,
12, 22 },
{ 12, 27,
13, 28 }
};
// put actual indexes values into array too
Align::Hypothesis *result = sc->get_result();
Align::Hypothesis::iterator seq = result->begin();
int exp = 0;
while (seq != result->end()) {
EXPECT_EQ(expected_sequence[exp], std::vector<int>(**seq));
++seq;
++exp;
}
}
TEST_F(AlignTest, SequenceTestExpand) {
sc->initial_sequences();
sc->expand_sequences();
std::vector<std::vector<int>> expected_sequence {
{ 8, 19,
9, 20 },
{ 10, 21,
12, 22,
13, 23 },
{ 12, 27,
13, 28,
17, 30 }
};
std::vector<std::vector<int>> actual_sequence = *(sc->get_result());
EXPECT_EQ(expected_sequence.size(), actual_sequence.size());
EXPECT_EQ(expected_sequence, actual_sequence);
}
TEST_F(AlignTest, SequenceTestMerge) {
sc->initial_sequences();
sc->expand_sequences();
sc->merge_sequences();
std::vector<std::vector<int>> expected = {
{ 8, 19,
9, 20,
10, 21,
12, 22,
13, 23 },
{ 12, 27,
13, 28,
17, 30 }
};
std::vector<std::vector<int>> actual = *(sc->get_result());
EXPECT_EQ(expected, actual);
}
TEST_F(AlignTest, TestAll) {
sc->initial_sequences();
sc->expand_sequences();
sc->merge_sequences();
sc->collect_scores();
sc->get_topranking();
std::vector<std::vector<int>> expected { {
8, 19,
9, 20,
10, 21,
12, 22,
13, 23
} };
std::vector<std::vector<int>> actual = *(sc->get_result());
EXPECT_EQ(expected.size(), actual.size());
EXPECT_EQ(expected, actual);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}