1 | #include "sort_file.h" |
---|
2 | #include "sort_file_dynamic.h" |
---|
3 | #include "entry_test.h" |
---|
4 | #include <iostream> |
---|
5 | |
---|
6 | using namespace hierarchy_memory::sort_file; |
---|
7 | using namespace std; |
---|
8 | |
---|
9 | void test_ko (int val) |
---|
10 | { |
---|
11 | cout << "***** Test(" << val << ") KO *****" << endl; |
---|
12 | exit (val); |
---|
13 | }; |
---|
14 | |
---|
15 | void test_ok () |
---|
16 | { |
---|
17 | cout << "***** Test OK *****" << endl; |
---|
18 | exit (0); |
---|
19 | }; |
---|
20 | |
---|
21 | static uint32_t num_test = 1; |
---|
22 | |
---|
23 | template <class T> |
---|
24 | void test(T exp1, T exp2) |
---|
25 | { |
---|
26 | if (exp1 != exp2) |
---|
27 | { |
---|
28 | cerr << "exp1 : " << exp1 << endl; |
---|
29 | cerr << "exp2 : " << exp2 << endl; |
---|
30 | test_ko (num_test); |
---|
31 | } |
---|
32 | num_test ++; |
---|
33 | }; |
---|
34 | |
---|
35 | int main () |
---|
36 | { |
---|
37 | { |
---|
38 | cout << "<main> Test de \"Sort_File\"" << endl; |
---|
39 | |
---|
40 | cout << " * creation d'une Sort_File de taille 5" << endl; |
---|
41 | Sort_File <Entry> my_Sort_File = Sort_File <Entry> (param_t("my_file",5)); |
---|
42 | my_Sort_File.reset(); |
---|
43 | cout << my_Sort_File << endl; |
---|
44 | |
---|
45 | cout << " * must be empty ..." << endl; |
---|
46 | if ( (my_Sort_File.empty() == false) || |
---|
47 | (my_Sort_File.full () == true ) ) |
---|
48 | test_ko (1); |
---|
49 | |
---|
50 | cout << " * insert 6 elements" << endl; |
---|
51 | |
---|
52 | if (my_Sort_File.push((uint32_t)5,Entry(1,1,0x44444444)) != true ) test_ko (2); cout << my_Sort_File << endl; |
---|
53 | if (my_Sort_File.push((uint32_t)6,Entry(2,2,0x55555555)) != true ) test_ko (3); cout << my_Sort_File << endl; |
---|
54 | if (my_Sort_File.push((uint32_t)3,Entry(3,3,0x22222222)) != true ) test_ko (4); cout << my_Sort_File << endl; |
---|
55 | if (my_Sort_File.push((uint32_t)5,Entry(4,4,0x33333333)) != true ) test_ko (5); cout << my_Sort_File << endl; |
---|
56 | if (my_Sort_File.push((uint32_t)1,Entry(5,5,0x11111111)) != true ) test_ko (6); cout << my_Sort_File << endl; |
---|
57 | if (my_Sort_File.push((uint32_t)4,Entry(6,6,0x00000BAD)) != false) test_ko (7); cout << my_Sort_File << endl; |
---|
58 | |
---|
59 | cout << " * must be full ..." << endl; |
---|
60 | if ( (my_Sort_File.empty() == true ) || |
---|
61 | (my_Sort_File.full () == false) ) |
---|
62 | test_ko (8); |
---|
63 | |
---|
64 | cout << " * extract 6 elements" << endl; |
---|
65 | if (my_Sort_File.pop().data != 0x11111111) test_ko (9); |
---|
66 | if (my_Sort_File.pop().data != 0x22222222) test_ko (10); |
---|
67 | if (my_Sort_File.pop().data != 0x33333333) test_ko (11); |
---|
68 | if (my_Sort_File.pop().data != 0x44444444) test_ko (12); |
---|
69 | if (my_Sort_File.pop().data != 0x55555555) test_ko (13); |
---|
70 | |
---|
71 | cout << " * ajout de 8 elements (reset apres le deuxieme)" << endl; |
---|
72 | |
---|
73 | if (my_Sort_File.push((uint32_t)5,Entry(1,1,0x44444444)) != true ) test_ko (14); cout << my_Sort_File << endl; |
---|
74 | if (my_Sort_File.push((uint32_t)6,Entry(2,2,0x55555555)) != true ) test_ko (15); cout << my_Sort_File << endl; |
---|
75 | my_Sort_File.reset(); |
---|
76 | if (my_Sort_File.push((uint32_t)3,Entry(3,3,0x22222222)) != true ) test_ko (16); cout << my_Sort_File << endl; |
---|
77 | if (my_Sort_File.push((uint32_t)5,Entry(4,4,0x33333333)) != true ) test_ko (17); cout << my_Sort_File << endl; |
---|
78 | if (my_Sort_File.push((uint32_t)5,Entry(1,1,0x44444444)) != true ) test_ko (18); cout << my_Sort_File << endl; |
---|
79 | if (my_Sort_File.push((uint32_t)7,Entry(2,2,0x55555555)) != true ) test_ko (19); cout << my_Sort_File << endl; |
---|
80 | if (my_Sort_File.push((uint32_t)1,Entry(5,5,0x11111111)) != true ) test_ko (20); cout << my_Sort_File << endl; |
---|
81 | if (my_Sort_File.push((uint32_t)4,Entry(6,6,0x00000BAD)) != false) test_ko (21); cout << my_Sort_File << endl; |
---|
82 | |
---|
83 | cout << " * 3 transitions" << endl; |
---|
84 | |
---|
85 | my_Sort_File.transition(); cout << my_Sort_File << endl; |
---|
86 | my_Sort_File.transition(); cout << my_Sort_File << endl; |
---|
87 | my_Sort_File.transition(); cout << my_Sort_File << endl; |
---|
88 | |
---|
89 | cout << " * extract 1 element" << endl; |
---|
90 | |
---|
91 | if (my_Sort_File.pop().data != 0x11111111) test_ko (22); |
---|
92 | |
---|
93 | cout << my_Sort_File << endl; |
---|
94 | |
---|
95 | for (uint32_t it = 0; it < my_Sort_File.nb_slot_use(); it ++) |
---|
96 | { |
---|
97 | slot_t<Entry> val = my_Sort_File.read(it); |
---|
98 | cout << val.delay << " " << val.data << endl; |
---|
99 | } |
---|
100 | |
---|
101 | cout << " * Test pop(n)" << endl; |
---|
102 | |
---|
103 | test <uint32_t> (my_Sort_File.pop(1).data, 0x44444444); |
---|
104 | test <uint32_t> (my_Sort_File.pop(2).data, 0x55555555); |
---|
105 | test <uint32_t> (my_Sort_File.pop(0).data, 0x22222222); |
---|
106 | test <uint32_t> (my_Sort_File.pop(0).data, 0x33333333); |
---|
107 | } |
---|
108 | |
---|
109 | { |
---|
110 | cout << "<main> Test de \"Sort_File_Dynamic\"" << endl; |
---|
111 | |
---|
112 | cout << " * creation d'une Sort_File de taille 5" << endl; |
---|
113 | Sort_File_Dynamic <Entry> my_Sort_File_Dynamic = Sort_File_Dynamic <Entry> (param_t("my_file_dynamic",5)); |
---|
114 | my_Sort_File_Dynamic.reset(); |
---|
115 | cout << my_Sort_File_Dynamic << endl; |
---|
116 | |
---|
117 | cout << " * must be empty ..." << endl; |
---|
118 | if ( (my_Sort_File_Dynamic.empty() == false) || |
---|
119 | (my_Sort_File_Dynamic.full () == true ) ) |
---|
120 | test_ko (1); |
---|
121 | |
---|
122 | if (my_Sort_File_Dynamic.push(5,Entry(1,1, 4)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
123 | if (my_Sort_File_Dynamic.push(6,Entry(2,2, 6)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
124 | if (my_Sort_File_Dynamic.push(3,Entry(3,3, 2)) != true ) test_ko ( 4); cout << my_Sort_File_Dynamic << endl; |
---|
125 | if (my_Sort_File_Dynamic.push(5,Entry(4,4, 5)) != true ) test_ko ( 5); cout << my_Sort_File_Dynamic << endl; |
---|
126 | if (my_Sort_File_Dynamic.push(1,Entry(5,5, 1)) != true ) test_ko ( 6); cout << my_Sort_File_Dynamic << endl; |
---|
127 | if (my_Sort_File_Dynamic.push(4,Entry(6,6, 3)) != true ) test_ko ( 7); cout << my_Sort_File_Dynamic << endl; |
---|
128 | if (my_Sort_File_Dynamic.push(9,Entry(1,1,12)) != true ) test_ko ( 8); cout << my_Sort_File_Dynamic << endl; |
---|
129 | if (my_Sort_File_Dynamic.push(6,Entry(2,2, 7)) != true ) test_ko ( 9); cout << my_Sort_File_Dynamic << endl; |
---|
130 | if (my_Sort_File_Dynamic.push(7,Entry(3,3, 8)) != true ) test_ko (10); cout << my_Sort_File_Dynamic << endl; |
---|
131 | if (my_Sort_File_Dynamic.push(7,Entry(4,4, 9)) != true ) test_ko (11); cout << my_Sort_File_Dynamic << endl; |
---|
132 | if (my_Sort_File_Dynamic.push(8,Entry(5,5,11)) != true ) test_ko (12); cout << my_Sort_File_Dynamic << endl; |
---|
133 | if (my_Sort_File_Dynamic.push(7,Entry(6,6,10)) != true ) test_ko (13); cout << my_Sort_File_Dynamic << endl; |
---|
134 | |
---|
135 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
136 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
137 | if (my_Sort_File_Dynamic.pop().data != 3 ) test_ko ( 4); cout << my_Sort_File_Dynamic << endl; |
---|
138 | if (my_Sort_File_Dynamic.pop().data != 4 ) test_ko ( 5); cout << my_Sort_File_Dynamic << endl; |
---|
139 | if (my_Sort_File_Dynamic.pop().data != 5 ) test_ko ( 6); cout << my_Sort_File_Dynamic << endl; |
---|
140 | if (my_Sort_File_Dynamic.pop().data != 6 ) test_ko ( 7); cout << my_Sort_File_Dynamic << endl; |
---|
141 | if (my_Sort_File_Dynamic.pop().data != 7 ) test_ko ( 8); cout << my_Sort_File_Dynamic << endl; |
---|
142 | if (my_Sort_File_Dynamic.pop().data != 8 ) test_ko ( 9); cout << my_Sort_File_Dynamic << endl; |
---|
143 | if (my_Sort_File_Dynamic.pop().data != 9 ) test_ko (10); cout << my_Sort_File_Dynamic << endl; |
---|
144 | if (my_Sort_File_Dynamic.pop().data != 10 ) test_ko (11); cout << my_Sort_File_Dynamic << endl; |
---|
145 | if (my_Sort_File_Dynamic.pop().data != 11 ) test_ko (12); cout << my_Sort_File_Dynamic << endl; |
---|
146 | if (my_Sort_File_Dynamic.pop().data != 12 ) test_ko (13); cout << my_Sort_File_Dynamic << endl; |
---|
147 | |
---|
148 | |
---|
149 | if (my_Sort_File_Dynamic.push(5,Entry(1,1, 4)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
150 | if (my_Sort_File_Dynamic.push(6,Entry(2,2, 6)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
151 | if (my_Sort_File_Dynamic.push(3,Entry(3,3, 2)) != true ) test_ko ( 4); cout << my_Sort_File_Dynamic << endl; |
---|
152 | if (my_Sort_File_Dynamic.push(5,Entry(4,4, 5)) != true ) test_ko ( 5); cout << my_Sort_File_Dynamic << endl; |
---|
153 | if (my_Sort_File_Dynamic.push(1,Entry(5,5, 1)) != true ) test_ko ( 6); cout << my_Sort_File_Dynamic << endl; |
---|
154 | if (my_Sort_File_Dynamic.push(4,Entry(6,6, 3)) != true ) test_ko ( 7); cout << my_Sort_File_Dynamic << endl; |
---|
155 | if (my_Sort_File_Dynamic.push(9,Entry(1,1,12)) != true ) test_ko ( 8); cout << my_Sort_File_Dynamic << endl; |
---|
156 | if (my_Sort_File_Dynamic.push(6,Entry(2,2, 7)) != true ) test_ko ( 9); cout << my_Sort_File_Dynamic << endl; |
---|
157 | if (my_Sort_File_Dynamic.push(7,Entry(3,3, 8)) != true ) test_ko (10); cout << my_Sort_File_Dynamic << endl; |
---|
158 | if (my_Sort_File_Dynamic.push(7,Entry(4,4, 9)) != true ) test_ko (11); cout << my_Sort_File_Dynamic << endl; |
---|
159 | if (my_Sort_File_Dynamic.push(8,Entry(5,5,11)) != true ) test_ko (12); cout << my_Sort_File_Dynamic << endl; |
---|
160 | if (my_Sort_File_Dynamic.push(7,Entry(6,6,10)) != true ) test_ko (13); cout << my_Sort_File_Dynamic << endl; |
---|
161 | |
---|
162 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
163 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
164 | |
---|
165 | if (my_Sort_File_Dynamic.push(0,Entry(1,1, 1)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
166 | if (my_Sort_File_Dynamic.push(0,Entry(2,2, 2)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
167 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
168 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
169 | if (my_Sort_File_Dynamic.push(0,Entry(1,1, 1)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
170 | if (my_Sort_File_Dynamic.push(0,Entry(2,2, 2)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
171 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
172 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
173 | if (my_Sort_File_Dynamic.push(0,Entry(1,1, 1)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
174 | if (my_Sort_File_Dynamic.push(0,Entry(2,2, 2)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
175 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
176 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
177 | if (my_Sort_File_Dynamic.push(0,Entry(1,1, 1)) != true ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
178 | if (my_Sort_File_Dynamic.push(0,Entry(2,2, 2)) != true ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
179 | if (my_Sort_File_Dynamic.pop().data != 1 ) test_ko ( 2); cout << my_Sort_File_Dynamic << endl; |
---|
180 | if (my_Sort_File_Dynamic.pop().data != 2 ) test_ko ( 3); cout << my_Sort_File_Dynamic << endl; |
---|
181 | } |
---|
182 | |
---|
183 | test_ok (); |
---|
184 | |
---|
185 | } |
---|