1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : fb_test.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Wolfram Foerster in October 2002 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "ps_bitmap.hxx" |
---|
13 | #include "ps_node.hxx" |
---|
14 | |
---|
15 | #include <iostream> |
---|
16 | |
---|
17 | #include <sys/times.h> |
---|
18 | |
---|
19 | static void runtests(FILE *out, const char *outputfile) { |
---|
20 | // output gets logged by unittest |
---|
21 | // expected result is in ../UNIT_TESTER/run/tools/probeset.out.expected |
---|
22 | |
---|
23 | { |
---|
24 | PS_BitSet_Fast *x = new PS_BitSet_Fast(false, 20); |
---|
25 | x->setTrue(0); |
---|
26 | x->setTrue(3); |
---|
27 | x->setTrue(4); |
---|
28 | x->setTrue(7); |
---|
29 | x->setTrue(10); |
---|
30 | x->setTrue(11); |
---|
31 | x->setTrue(14); |
---|
32 | x->print(out, true, 20); |
---|
33 | |
---|
34 | fprintf(out, "true index count = %li\n", x->getCountOfTrues()); |
---|
35 | |
---|
36 | PS_BitSet::IndexSet indices; |
---|
37 | |
---|
38 | x->getTrueIndices(indices); |
---|
39 | fprintf(out, " true indices (%2zu) : ", indices.size()); |
---|
40 | for (PS_BitSet::IndexSet::iterator i=indices.begin(); i != indices.end(); ++i) { |
---|
41 | fprintf(out, " %4li", *i); |
---|
42 | } |
---|
43 | fputc('\n', out); |
---|
44 | |
---|
45 | x->getTrueIndices(indices, 15); |
---|
46 | fprintf(out, " true indices (%2zu) : ", indices.size()); |
---|
47 | for (PS_BitSet::IndexSet::iterator i=indices.begin(); i != indices.end(); ++i) { |
---|
48 | fprintf(out, " %4li", *i); |
---|
49 | } |
---|
50 | fputc('\n', out); |
---|
51 | |
---|
52 | x->getFalseIndices(indices); |
---|
53 | fprintf(out, " false indices (%2zu) : ", indices.size()); |
---|
54 | for (PS_BitSet::IndexSet::iterator i=indices.begin(); i != indices.end(); ++i) { |
---|
55 | fprintf(out, " %4li", *i); |
---|
56 | } |
---|
57 | fputc('\n', out); |
---|
58 | |
---|
59 | x->getFalseIndices(indices, 15); |
---|
60 | fprintf(out, " false indices (%2zu) : ", indices.size()); |
---|
61 | for (PS_BitSet::IndexSet::iterator i=indices.begin(); i != indices.end(); ++i) { |
---|
62 | fprintf(out, " %4li", *i); |
---|
63 | } |
---|
64 | fputc('\n', out); |
---|
65 | |
---|
66 | delete x; |
---|
67 | } |
---|
68 | |
---|
69 | { |
---|
70 | PS_BitMap *map = new PS_BitMap_Fast(false, 10); |
---|
71 | for (long i = 0; i < 10; ++i) { |
---|
72 | map->set(i, i, true); |
---|
73 | map->set(0, i, true); |
---|
74 | map->set(i, 0, true); |
---|
75 | map->set(9, i, true); |
---|
76 | } |
---|
77 | map->print(out); |
---|
78 | |
---|
79 | PS_FileBuffer *fb1 = new PS_FileBuffer(outputfile, PS_FileBuffer::WRITEONLY); |
---|
80 | map->save(fb1); |
---|
81 | fb1->reinit(outputfile, PS_FileBuffer::READONLY); |
---|
82 | PS_BitMap_Counted *map2 = new PS_BitMap_Counted(fb1); |
---|
83 | map2->print(out); |
---|
84 | |
---|
85 | // map2->setTrue(5, 8); // exceeds capacity |
---|
86 | map2->setTrue(5, 7); |
---|
87 | map2->print(out); |
---|
88 | map2->recalcCounters(); |
---|
89 | map2->print(out); |
---|
90 | |
---|
91 | delete map; |
---|
92 | delete map2; |
---|
93 | delete fb1; |
---|
94 | } |
---|
95 | |
---|
96 | { |
---|
97 | char str[] = "ABCDEFG"; |
---|
98 | int a = 1; |
---|
99 | int b = 1; |
---|
100 | fprintf(out, "%i %c %i\n", a, str[a], a+1); a++; |
---|
101 | fprintf(out, "%i %c %i\n", b, str[b+1], b+1); b++; |
---|
102 | } |
---|
103 | { |
---|
104 | ID2IDSet *s = new ID2IDSet; |
---|
105 | s->insert(ID2IDPair(10, 40)); |
---|
106 | s->insert(ID2IDPair(8, 20)); |
---|
107 | s->insert(ID2IDPair(1, 4)); |
---|
108 | s->insert(ID2IDPair(8, 40)); |
---|
109 | s->insert(ID2IDPair(40, 70)); |
---|
110 | s->insert(ID2IDPair(20, 80)); |
---|
111 | for (ID2IDSetCIter i = s->begin(); i != s->end(); ++i) { |
---|
112 | fprintf(out, "%6i %6i\n", i->first, i->second); |
---|
113 | } |
---|
114 | delete s; |
---|
115 | } |
---|
116 | |
---|
117 | { |
---|
118 | PS_FileBuffer *fb2 = new PS_FileBuffer(outputfile, true); |
---|
119 | char *data = (char *)malloc(1024); |
---|
120 | // fb2->get(data, 4096); |
---|
121 | fb2->get(data, 100); |
---|
122 | |
---|
123 | free(data); |
---|
124 | delete fb2; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | int ARB_main(int , char *[]) { |
---|
129 | runtests(stdout, "testdata"); |
---|
130 | return 0; |
---|
131 | } |
---|
132 | |
---|
133 | // -------------------------------------------------------------------------------- |
---|
134 | |
---|
135 | #include <arb_msg.h> |
---|
136 | #include <arb_file.h> |
---|
137 | #include <arb_diff.h> |
---|
138 | |
---|
139 | #ifdef UNIT_TESTS |
---|
140 | #ifndef TEST_UNIT_H |
---|
141 | #include <test_unit.h> |
---|
142 | #endif |
---|
143 | |
---|
144 | // #define TEST_AUTO_UPDATE // uncomment to update expected results |
---|
145 | |
---|
146 | void TEST_probeset_basics() { |
---|
147 | const char *textout = "tools/probeset.out"; |
---|
148 | const char *dataout = "tools/probeset.data"; |
---|
149 | |
---|
150 | GB_unlink(dataout); |
---|
151 | |
---|
152 | FILE *out = fopen(textout, "wt"); |
---|
153 | if (!out) { |
---|
154 | TEST_EXPECT_NO_ERROR(GB_IO_error("writing", textout)); |
---|
155 | } |
---|
156 | runtests(out, dataout); |
---|
157 | fclose(out); |
---|
158 | |
---|
159 | const char *textout_expected = "tools/probeset.out.expected"; |
---|
160 | const char *dataout_expected = "tools/probeset.data.expected"; |
---|
161 | |
---|
162 | #if defined(TEST_AUTO_UPDATE) |
---|
163 | TEST_COPY_FILE(textout, textout_expected); |
---|
164 | TEST_COPY_FILE(dataout, dataout_expected); |
---|
165 | #else // !defined(TEST_AUTO_UPDATE) |
---|
166 | TEST_EXPECT_TEXTFILES_EQUAL(textout, textout_expected); |
---|
167 | TEST_EXPECT_FILES_EQUAL(dataout, dataout_expected); |
---|
168 | #endif |
---|
169 | |
---|
170 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(textout)); |
---|
171 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(dataout)); |
---|
172 | } |
---|
173 | |
---|
174 | #endif // UNIT_TESTS |
---|
175 | |
---|
176 | // -------------------------------------------------------------------------------- |
---|