-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_storage.cxx
102 lines (80 loc) · 2.16 KB
/
test_storage.cxx
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
#include "godtest.h"
#include "comparable.h"
libgod::Point randPoint (size_t dp, size_t dc)
{
libgod::Point p(dp,dc);
for (size_t i = 0; i < dp; ++i)
p.setParameterAt(i, 1.0 * rand() / RAND_MAX);
for (size_t i = 0; i < dc; ++i)
p.setCriterionAt(i, 1.0 * rand() / RAND_MAX);
return p;
}
const size_t dp = 2, dc = 3;
TEST(Storage, Numeric)
{
libgod::Union aunion(dp,dc);
libgod::Set& aset1 = aunion.add();
aset1.add(randPoint(dp,dc));
aset1.add(randPoint(dp,dc));
// should assert because of possible segfault
ASSERT_EQ(aunion.size(), 1);
EXPECT_EQ(aunion[0].size(), 2);
libgod::Set& aset2 = aunion.add();
aset2.add(randPoint(dp,dc));
aset2.add(randPoint(dp,dc));
aset2.add(randPoint(dp,dc));
// should assert because of possible segfault
ASSERT_EQ(aunion.size(), 2);
EXPECT_EQ(aunion[1].size(), 3);
EXPECT_EQ(aunion[0].size(), 2);
// should assert because of possible segfault
ASSERT_EQ(aunion.dimParameter(), dp);
EXPECT_EQ(aunion[0].dimParameter(), dp);
EXPECT_EQ(aunion[0][0].dimParameter(), dp);
}
TEST(Storage, ReadWrite)
{
libgod::Union aunion(dp,dc);
libgod::Set& aset1 = aunion.add();
aset1.add(randPoint(dp,dc));
aset1.add(randPoint(dp,dc));
libgod::Set& aset2 = aunion.add();
aset2.add(randPoint(dp,dc));
aset2.add(randPoint(dp,dc));
aset2.add(randPoint(dp,dc));
libgod::Storage storage("../tmp.asn1");
storage.write(aunion);
std::ostringstream oss1;
oss1 << aunion;
libgod::Union nunion(dp,dc);
storage.read(nunion);
std::ostringstream oss2;
oss2 << nunion;
EXPECT_EQ(aunion.size(), dp);
EXPECT_EQ(aunion.size(), nunion.size());
EXPECT_EQ(oss1.str(), oss2.str());
}
void ReadNonExistentFileHelper()
{
libgod::Union u;
libgod::Storage storage("../notfound");
storage.read(u);
}
TEST(Storage, ReadNonExistentFile)
{
EXPECT_THROW(ReadNonExistentFileHelper(), libgod::GodError);
}
TEST(Storage, StreamOut)
{
libgod::Union aunion(dp,dc);
libgod::Set& aset = aunion.add();
aset.add(randPoint(dp,dc));
aset.add(randPoint(dp,dc));
// test operator<<
// TODO make more deep test, now we are sure
// that they doesn't fail
std::ostringstream oss;
oss << aunion << std::endl;
oss << aset << std::endl;
oss << aset[0] << std::endl;
}