-
Notifications
You must be signed in to change notification settings - Fork 1
/
Topology_tests.hh
126 lines (104 loc) · 4.01 KB
/
Topology_tests.hh
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
#ifndef TOPOLOGY_TESTS_HH
#define TOPOLOGY_TESTS_HH
#include "suffixtree_brute.hh"
#include "brute_tools.hh"
#include "Precalc.hh"
#include <string>
#include <sstream>
using namespace std;
template <typename T>
string vec_to_string(vector<T>& v){
stringstream ss;
for(int64_t i = 0; i < v.size(); i++){
ss << v[i];
if(i != v.size() - 1)
ss << ",";
}
return ss.str();
}
sdsl::bit_vector to_sdsl(const vector<bool>& v){
sdsl::bit_vector u(v.size(),0);
for(int64_t i = 0; i < v.size(); i++)
u[i] = v[i];
return u;
}
void test_brute_bpr_building(){
string text = "abracabra";
std::reverse(text.begin(), text.end());
BD_BWT_index<> index((uint8_t*)text.c_str());
vector<Edge> ST = get_suffix_tree(text + '$');
vector<bool> bpr = ST_to_bpr(ST);
vector<bool> rev_st_topology_correct = {1,1,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,0}; // hand checked
assert(bpr == rev_st_topology_correct);
}
void test_rev_st_bpr_building(){
srand(525720);
for(int64_t reps = 0; reps < 100; reps++){
string S = get_random_string(100, 3);
BD_BWT_index<> index((uint8_t*)S.c_str());
sdsl::bit_vector rev_st_bpr = get_rev_st_topology(index);
string S_rev(S.rbegin(), S.rend());
vector<Edge> ST = get_suffix_tree(S_rev + '$');
sdsl::bit_vector bpr_brute = to_sdsl(ST_to_bpr(ST));
assert(rev_st_bpr == bpr_brute);
}
cout << "Rev ST full topology building OK" << endl;
}
void test_maxrep_rev_st_bpr_building(){
// Testing maxreps + left extensions of maxreps
srand(552340);
for(int64_t reps = 0; reps < 100; reps++){
string S = get_random_string(100, 3);
BD_BWT_index<> index((uint8_t*)S.c_str());
Rev_ST_Maxrep_Iterator iter(&index);
sdsl::bit_vector rev_st_bpr = get_rev_st_bpr_and_pruning(index,iter).bpr;
string S_rev(S.rbegin(), S.rend());
vector<Edge> ST = get_suffix_tree(S_rev + '$');
set<string> maxreps = get_maxreps(S_rev);
vector<Edge> ST_maxreps;
for(Edge E : ST){
if(maxreps.find(E.from) != maxreps.end()){
// Origin of edge is a maxrep
ST_maxreps.push_back(E);
}
}
sdsl::bit_vector bpr_brute = to_sdsl(ST_to_bpr(ST_maxreps));
assert(rev_st_bpr == bpr_brute);
}
cout << "Rev ST maxrep left extension topology building OK" << endl;
}
void test_maxrep_depth_bounded_rev_st_bpr_building(){
// Testing maxreps + left extensions of maxreps
srand(12131412);
for(int64_t reps = 0; reps < 100; reps++){
string S = get_random_string(100, 3);
int64_t depth_bound = 3;
BD_BWT_index<> index((uint8_t*)S.c_str());
Rev_ST_Depth_Bounded_Maxrep_Iterator iter(&index, depth_bound);
sdsl::bit_vector rev_st_bpr = get_rev_st_bpr_and_pruning(index,iter).bpr;
string S_rev(S.rbegin(), S.rend());
vector<Edge> ST = get_suffix_tree(S_rev + '$');
set<string> maxreps = get_maxreps(S_rev);
vector<Edge> ST_maxreps;
for(Edge E : ST){
if(maxreps.find(E.from) != maxreps.end() && E.from.size() < depth_bound){
// Origin of edge is a maxrep
ST_maxreps.push_back(E);
}
}
sdsl::bit_vector bpr_brute = to_sdsl(ST_to_bpr(ST_maxreps));
/*
ofstream full("aaa/full.dot");
full << ST_to_dot(get_suffix_tree(S_rev + '$'), maxreps) << endl;
ofstream dot("aaa/right.dot");
dot << ST_to_dot(ST_maxreps, maxreps) << endl;
ofstream bprwrong("aaa/wrong.bpr");
bprwrong << rev_st_bpr << endl;
cout << "todo: remember to delete file writes" << endl;
//cout << "right: " << bpr_brute << endl;
//cout << "wrong: " << rev_st_bpr << endl; */
assert(rev_st_bpr == bpr_brute);
}
cout << "Rev ST depth bounded maxrep left extension topology building OK" << endl;
}
#endif