-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_desa.cpp
154 lines (116 loc) · 4.31 KB
/
test_desa.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
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
150
151
152
153
154
#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <utility>
#include <mxx/env.hpp>
#include <mxx/comm.hpp>
#include <mxx/file.hpp>
#include <mxx/distribution.hpp>
#include <suffix_array.hpp>
#include <lcp.hpp>
#include <divsufsort_wrapper.hpp>
#include "seq_query.hpp"
#include "desa.hpp"
#include "tldt.hpp"
using index_t = uint64_t;
using range_t = dist_desa<index_t>::range_t;
inline std::vector<std::pair<std::string, range_t>> mississippi_testcase() {
using r = range_t;
std::vector<std::pair<std::string, range_t>> patterns;
patterns.emplace_back("i", r(0,4));
patterns.emplace_back("mississip", r(4,5));
patterns.emplace_back("ss", r(9,11));
patterns.emplace_back("pp", r(6,7));
patterns.emplace_back("m", r(4,5));
patterns.emplace_back("pi", r(5,6));
patterns.emplace_back("is", r(2,4));
patterns.emplace_back("ssi", r(9,11));
patterns.emplace_back("p", r(5,7));
patterns.emplace_back("ississippi", r(3,4));
patterns.emplace_back("si", r(7,9));
patterns.emplace_back("miss", r(4,5));
patterns.emplace_back("s", r(7,11));
patterns.emplace_back("ip", r(1,2));
patterns.emplace_back("ppi", r(6,7));
patterns.emplace_back("mississippi", r(4,5));
return patterns;
}
TEST(DesaTest,MississippiLocatePossible) {
mxx::comm c;
ASSERT_TRUE(c.size() <= 7) << "the `mississippi` test shouldn't run with more processors than character pairs";
std::string s;
if (c.rank() == 0) {
s = "mississippi";
}
std::string input_str = mxx::stable_distribute(s, c);
// construct DESA
dist_desa<index_t> idx(c);
idx.construct(input_str.begin(), input_str.end(), c);
auto patterns = mississippi_testcase();
// locate single pattern in distributed representation (collective op)
for (auto pat : patterns) {
std::string P = pat.first;
range_t exp_res = pat.second;
range_t r = idx.locate_possible(P);
// (EXPECTED, ACTUAL)
EXPECT_EQ(exp_res, r);
}
}
TEST(DesaTest, FileIO) {
mxx::comm c;
ASSERT_TRUE(c.size() <= 7) << "the `mississippi` test shouldn't run with more processors than character pairs";
std::string s;
if (c.rank() == 0) {
s = "mississippi";
std::ofstream f("miss.str");
f.write(&s[0],s.size());
}
std::string input_str = mxx::stable_distribute(s, c);
// construct DESA
dist_desa<index_t> desa(c);
desa.construct(input_str.begin(), input_str.end(), c);
desa.write("desa_miss", c);
dist_desa<index_t> desa2(c);
desa2.read("miss.str", "desa_miss", c);
EXPECT_EQ(desa.sa.local_SA, desa2.sa.local_SA);
EXPECT_EQ(desa.sa.local_LCP, desa2.sa.local_LCP);
EXPECT_EQ(desa.sa.local_Lc, desa2.sa.local_Lc);
EXPECT_EQ(desa.tli.idx.table, desa2.tli.idx.table);
EXPECT_EQ(desa.tli.idx.alpha, desa2.tli.idx.alpha);
// TODO: implement test for loading with smaller/larger nuber of processors
// and still check that querying works correctly
// -> introduce function to test queries for a given desa
}
#define PV(x, c) mxx::sync_cout(c) << "[" << c.rank() << "] " << "" # x " = " << x << std::endl;
TEST(DesaTest,MississippiBulkLocatePossible) {
mxx::comm c;
ASSERT_TRUE(c.size() <= 7) << "the `mississippi` test shouldn't run with more processors than character pairs";
std::string s;
if (c.rank() == 0) {
s = "mississippi";
}
std::string input_str = mxx::stable_distribute(s, c);
// construct DESA
dist_desa<index_t, tldt<index_t>> idx(c);
idx.construct(input_str.begin(), input_str.end(), c);
PV(input_str, c);
PV(idx.sa.local_LCP, c);
PV(idx.sa.local_SA, c);
PV(idx.tli.prefix(), c);
PV(idx.tli.idx.LCP, c);
// create `strings` from patterns
auto patterns = mississippi_testcase();
mxx::blk_dist dist(patterns.size(), c.size(), c.rank());
std::vector<std::string> my_patterns(dist.local_size());
for (size_t i = 0; i < dist.local_size(); ++i) {
my_patterns[i] = patterns[i+dist.eprefix_size()].first;
}
strings ss = strings::from_vec(my_patterns);
std::vector<range_t> mysols = idx.bulk_locate(ss);
// check results
for (size_t i = 0; i < dist.local_size(); ++i) {
EXPECT_EQ(patterns[i+dist.eprefix_size()].second, mysols[i]);
}
}