forked from Preparation-Publication-BD2K/db_compress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompression_test.cpp
60 lines (51 loc) · 1.43 KB
/
compression_test.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
#include "base.h"
#include "compression.h"
#include "data_io.h"
#include "model.h"
#include "unit_test.h"
#include <vector>
#include <iostream>
namespace db_compress {
Schema schema;
CompressionConfig config;
Tuple tuple(2);
void PrepareData() {
RegisterAttrModel(0, new MockModelCreator(2));
std::vector<int> schema_; schema_.push_back(0); schema_.push_back(0);
schema = Schema(schema_);
config.allowed_err.push_back(0.01);
config.allowed_err.push_back(0.01);
config.sort_by_attr = -1;
tuple.attr[0] = new MockAttr(0);
tuple.attr[1] = new MockAttr(1);
}
void TestCompression() {
Compressor compressor("compression_test.txt", schema, config);
while (1) {
compressor.ReadTuple(tuple);
compressor.ReadTuple(tuple);
compressor.EndOfData();
if (!compressor.RequireMoreIterations())
break;
}
std::ifstream fin("compression_test.txt");
char c;
std::vector<unsigned char> file;
while (fin.get(c)) {
file.push_back((unsigned char) c);
}
unsigned char correct_answer[] = {1, 0, 0, 0, 1, 0, 2, 0, 2, 0x5c};
if (file.size() != 10)
std::cerr << "Compression Unit Test Failed!\n";
for (int i = 0; i < 10; ++i)
if (file[i] != correct_answer[i])
std::cerr << "Compression Unit Test Failed!\n";
}
void Test() {
PrepareData();
TestCompression();
}
} // namespace db_compress
int main() {
db_compress::Test();
}