Line data Source code
1 : //
2 : // Author: Saprykin Dmitry <saprykin.dmitry@gmail.com>, (C) 2014
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #include <fas/testing.hpp>
8 : #include <vset/vtree/vtree.hpp>
9 : #include <vset/vtree/strategy.hpp>
10 : #include <vset/compare.hpp>
11 :
12 : typedef vset::vtree::vtree< vset::vtree::strategy::vtree_fsb_inmem<int, std::greater<int>, 3> > int_vtree;
13 :
14 3 : UNIT(vtree_compare1, "")
15 : {
16 : using namespace fas::testing;
17 : using namespace vset;
18 :
19 : {
20 2 : int_vtree tree1, tree2;
21 4 : for (int i = 1; i < 4; ++i)
22 : {
23 3 : tree1.insert(i);
24 3 : tree2.insert(4-i);
25 : }
26 1 : t << is_true<expect>(tree1 == tree2);
27 2 : t << is_true<expect>(tree2 == tree1);
28 : }
29 1 : }
30 :
31 3 : UNIT(vtree_compare2, "")
32 : {
33 : using namespace fas::testing;
34 : using namespace vset;
35 :
36 : {
37 2 : int_vtree tree1, tree2;
38 4 : for (int i = 1; i < 4; ++i)
39 : {
40 3 : tree1.insert(2);
41 3 : tree2.insert(2);
42 : }
43 1 : tree2.insert(2);
44 1 : t << is_false<expect>(tree1 == tree2);
45 2 : t << is_false<expect>(tree2 == tree1);
46 : }
47 :
48 1 : }
49 :
50 3 : UNIT(vtree_compare3, "")
51 : {
52 : using namespace fas::testing;
53 : using namespace vset;
54 :
55 : {
56 2 : int_vtree tree1, tree2;
57 1 : tree1.insert(2); tree2.insert(2);
58 1 : tree1.insert(2); tree2.insert(1);
59 1 : tree1.insert(2); tree2.insert(2);
60 2 : t << is_false<expect>(tree1 == tree2);
61 : }
62 :
63 1 : }
64 :
65 3 : UNIT(vtree_compare4, "")
66 : {
67 : using namespace fas::testing;
68 : using namespace vset;
69 :
70 : {
71 2 : int_vtree tree1, tree2;
72 1 : tree1.insert(2); tree2.insert(2);
73 1 : tree1.insert(2); tree2.insert(2);
74 1 : tree1.insert(2); tree2.insert(2);
75 1 : t << is_false<expect>(tree1 < tree2);
76 2 : t << is_false<expect>(tree2 < tree1);
77 : }
78 1 : }
79 :
80 3 : UNIT(vtree_compare5, "")
81 : {
82 : using namespace fas::testing;
83 : using namespace vset;
84 :
85 : {
86 2 : int_vtree tree1, tree2;
87 1 : tree1.insert(2); tree2.insert(2);
88 1 : tree1.insert(2); tree2.insert(1);
89 1 : tree1.insert(2); tree2.insert(2);
90 1 : tree1.insert(3);
91 :
92 2 : t << is_true<expect>(tree1 < tree2);
93 : }
94 1 : }
95 :
96 3 : UNIT(vtree_compare6, "")
97 : {
98 : using namespace fas::testing;
99 : using namespace vset;
100 : {
101 2 : int_vtree tree1, tree2;
102 1 : tree1.insert(2); tree2.insert(2);
103 1 : tree1.insert(2); tree2.insert(2);
104 1 : tree1.insert(2); tree2.insert(55);
105 2 : t << is_true<expect>(tree2 < tree1);
106 : }
107 1 : }
108 :
109 : namespace {
110 : struct foo
111 : {
112 : int a;
113 : int b;
114 : };
115 :
116 : struct foo_compare: vset::compare_list< fas::type_list_n<
117 : vset::compare_member< foo, int, &foo::a, std::less<int> >,
118 : vset::compare_member< foo, int, &foo::b, std::greater<int> >
119 : >::type >{};
120 :
121 : typedef vset::vtree::vtree< vset::vtree::strategy::vtree_fsb_inmem<foo, foo_compare, 3> > foo_vtree;
122 : }
123 :
124 3 : UNIT(vtree_compare7, "")
125 : {
126 : using namespace fas::testing;
127 : using namespace vset;
128 : {
129 : foo f;
130 2 : foo_vtree tree1, tree2;
131 1 : f.a = 1; f.b = 1;
132 1 : tree1.insert(f);
133 1 : f.a = 1; f.b = 1;
134 1 : tree1.insert(f);
135 1 : f.a = 1; f.b = 1;
136 1 : tree1.insert(f);
137 1 : f.a = 1; f.b = 1;
138 1 : tree2.insert(f);
139 1 : f.a = 1; f.b = 1;
140 1 : tree2.insert(f);
141 1 : f.a = 1; f.b = 2;
142 1 : tree2.insert(f);
143 :
144 2 : t << is_true<expect>(tree2 < tree1);
145 : }
146 1 : }
147 :
148 1 : BEGIN_SUITE(vtree_compare_suite, "")
149 : ADD_UNIT(vtree_compare1)
150 : ADD_UNIT(vtree_compare2)
151 : ADD_UNIT(vtree_compare3)
152 : ADD_UNIT(vtree_compare4)
153 : ADD_UNIT(vtree_compare5)
154 : ADD_UNIT(vtree_compare6)
155 : ADD_UNIT(vtree_compare7)
156 7 : END_SUITE(vtree_compare_suite)
|