Mercurial > public > cpp-enigma
comparison enigma/tests/test_plugboard.t.h @ 9:7362965f53b1
Added tests for the hill climbing functions in the plugboard class.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 29 Jun 2012 21:19:00 -0500 |
parents | f4e25e6b76c3 |
children | 232dbe7a3fe0 |
comparison
equal
deleted
inserted
replaced
8:b90a41f0cd94 | 9:7362965f53b1 |
---|---|
2 // This file is part of Cpp-Enigma, the Enigma Machine simulation. | 2 // This file is part of Cpp-Enigma, the Enigma Machine simulation. |
3 // Cpp-Enigma is released under the MIT License (see License.txt). | 3 // Cpp-Enigma is released under the MIT License (see License.txt). |
4 // | 4 // |
5 // test_plugboard.t.h - Unit tests for the plugboard class. | 5 // test_plugboard.t.h - Unit tests for the plugboard class. |
6 | 6 |
7 #include <algorithm> | |
7 #include <cxxtest/TestSuite.h> | 8 #include <cxxtest/TestSuite.h> |
8 #include "plugboard.h" | 9 #include "plugboard.h" |
9 | 10 |
10 using namespace enigma; | 11 using namespace enigma; |
11 | 12 |
136 { | 137 { |
137 std::string stecker{"1/2 3/4 5/6 7/8 9/10 11/12 13/14 15/16 17/18 19/20"}; | 138 std::string stecker{"1/2 3/4 5/6 7/8 9/10 11/12 13/14 15/16 17/18 19/20"}; |
138 plugboard p{stecker}; | 139 plugboard p{stecker}; |
139 TS_ASSERT_EQUALS(stecker, p.navy_str()); | 140 TS_ASSERT_EQUALS(stecker, p.navy_str()); |
140 } | 141 } |
142 | |
143 void test_get_wiring() | |
144 { | |
145 plugboard pb; | |
146 alpha_int_array w(pb.get_wiring()); | |
147 | |
148 for (int i = 0; i < 26; ++i) | |
149 { | |
150 TS_ASSERT_EQUALS(w[i], i); | |
151 } | |
152 | |
153 pb.connect(0, 1); | |
154 pb.connect(8, 20); | |
155 pb.connect(24, 25); | |
156 for (int i = 0; i < 26; ++i) | |
157 { | |
158 w[i] = i; | |
159 } | |
160 std::swap(w[0], w[1]); | |
161 std::swap(w[8], w[20]); | |
162 std::swap(w[24], w[25]); | |
163 | |
164 alpha_int_array w1(pb.get_wiring()); | |
165 for (int i = 0; i < 26; ++i) | |
166 { | |
167 TS_ASSERT_EQUALS(w[i], w1[i]); | |
168 } | |
169 } | |
170 | |
171 void test_set_wiring() | |
172 { | |
173 alpha_int_array w; | |
174 for (int i = 0; i < 26; ++i) | |
175 { | |
176 w[i] = i; | |
177 } | |
178 std::swap(w[0], w[1]); | |
179 std::swap(w[8], w[20]); | |
180 std::swap(w[24], w[25]); | |
181 | |
182 plugboard pb; | |
183 pb.set_wiring(w); | |
184 | |
185 alpha_int_array w2 = pb.get_wiring(); | |
186 TS_ASSERT_EQUALS(w, w2); | |
187 } | |
188 | |
189 void test_is_wired() | |
190 { | |
191 plugboard pb; | |
192 pb.connect(0, 25); | |
193 pb.connect(4, 18); | |
194 for (int i = 0; i < 26; ++i) | |
195 { | |
196 if (i == 0 || i == 25 || i == 4 || i == 18) | |
197 { | |
198 TS_ASSERT(pb.is_wired(i)); | |
199 } | |
200 else | |
201 { | |
202 TS_ASSERT(!pb.is_wired(i)); | |
203 } | |
204 } | |
205 } | |
206 | |
207 void test_is_free() | |
208 { | |
209 plugboard pb; | |
210 pb.connect(0, 25); | |
211 pb.connect(4, 18); | |
212 for (int i = 0; i < 26; ++i) | |
213 { | |
214 if (i == 0 || i == 25 || i == 4 || i == 18) | |
215 { | |
216 TS_ASSERT(!pb.is_free(i)); | |
217 } | |
218 else | |
219 { | |
220 TS_ASSERT(pb.is_free(i)); | |
221 } | |
222 } | |
223 } | |
224 | |
225 void test_disconnect() | |
226 { | |
227 plugboard pb; | |
228 pb.connect(0, 25); | |
229 pb.connect(4, 18); | |
230 pb.disconnect(0); | |
231 pb.disconnect(18); | |
232 for (int i = 0; i < 26; ++i) | |
233 { | |
234 TS_ASSERT(pb.is_free(i)); | |
235 } | |
236 } | |
237 | |
238 void test_disconnect2() | |
239 { | |
240 plugboard pb; | |
241 for (int i = 0; i < 26; ++i) | |
242 { | |
243 pb.disconnect(i); | |
244 } | |
245 for (int i = 0; i < 26; ++i) | |
246 { | |
247 TS_ASSERT(pb.is_free(i)); | |
248 } | |
249 } | |
250 | |
251 void test_connect() | |
252 { | |
253 plugboard pb; | |
254 pb.connect(2, 4); | |
255 pb.connect(17, 20); | |
256 for (int i = 0; i < 26; ++i) | |
257 { | |
258 if (i == 2 || i == 4 || i == 17 || i == 20) | |
259 { | |
260 TS_ASSERT(pb.is_wired(i)); | |
261 } | |
262 else | |
263 { | |
264 TS_ASSERT(pb.is_free(i)); | |
265 } | |
266 } | |
267 pb.connect(20, 25); | |
268 for (int i = 0; i < 26; ++i) | |
269 { | |
270 if (i == 2 || i == 4 || i == 25 || i == 20) | |
271 { | |
272 TS_ASSERT(pb.is_wired(i)); | |
273 } | |
274 else | |
275 { | |
276 TS_ASSERT(pb.is_free(i)); | |
277 } | |
278 } | |
279 } | |
280 | |
281 void test_is_connected() | |
282 { | |
283 plugboard pb; | |
284 pb.connect(5, 7); | |
285 pb.connect(1, 20); | |
286 TS_ASSERT(pb.is_connected(5, 7)); | |
287 TS_ASSERT(pb.is_connected(1, 20)); | |
288 | |
289 for (int i = 0; i < 26; ++i) | |
290 { | |
291 if (i == 7) | |
292 { | |
293 TS_ASSERT(pb.is_connected(5, i)); | |
294 } | |
295 else | |
296 { | |
297 TS_ASSERT(!pb.is_connected(5, i)); | |
298 } | |
299 if (i == 1) | |
300 { | |
301 TS_ASSERT(pb.is_connected(20, i)); | |
302 } | |
303 else | |
304 { | |
305 TS_ASSERT(!pb.is_connected(20, i)); | |
306 } | |
307 } | |
308 } | |
309 | |
141 }; | 310 }; |