-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_interval.cpp
55 lines (43 loc) · 1.31 KB
/
test_interval.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
#include <gtest/gtest.h>
#include "intervals.h"
TEST(intervals, union_intersect) {
DisjointIntervals A;
DisjointIntervals B;
A.unionWith(B);
EXPECT_EQ(A, DisjointIntervals());
A.intersectionWith(B);
EXPECT_EQ(A, DisjointIntervals());
DisjointIntervals C({{0, 10}});
A.intersectionWith(C);
EXPECT_EQ(A, DisjointIntervals());
A.unionWith(C);
EXPECT_EQ(A, C);
DisjointIntervals D({{0, 3}});
A.unionWith(D);
EXPECT_EQ(A, C);
A.intersectionWith(D);
EXPECT_EQ(A, D);
DisjointIntervals E({{1, 5}});
A.intersectionWith(E);
EXPECT_EQ(A, DisjointIntervals({{1, 3}}));
DisjointIntervals F({{2, 4}});
A.unionWith(F);
EXPECT_EQ(A, DisjointIntervals({{1, 4}}));
DisjointIntervals G({{5, 6}});
A.intersectionWith(G);
EXPECT_EQ(A, DisjointIntervals());
DisjointIntervals H({{7, 8}});
G.unionWith(H);
EXPECT_EQ(G, DisjointIntervals({{5, 6}, {7, 8}}));
DisjointIntervals I({{5.5, 7.5}});
G.intersectionWith(I);
EXPECT_EQ(G, DisjointIntervals({{5.5, 6}, {7, 7.5}}));
DisjointIntervals J({{6, 7}});
G.unionWith(J);
EXPECT_EQ(G, DisjointIntervals({{5.5, 7.5}}));
for (auto &j : {A, B, C, D, E, F, G}) {
auto j_invinv = j;
j_invinv.inverse().inverse();
EXPECT_EQ(j, j_invinv);
}
}