Mercurial > public > cpp-enigma
comparison enigma/tests/test_machine.t.h @ 16:280facb82b80
Add the ability to change ring settings at the machine level.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 07 Jul 2012 11:42:31 -0500 |
parents | b90a41f0cd94 |
children |
comparison
equal
deleted
inserted
replaced
15:9e02d8696e67 | 16:280facb82b80 |
---|---|
251 | 251 |
252 TS_ASSERT_EQUALS(plaintext, truth_data); | 252 TS_ASSERT_EQUALS(plaintext, truth_data); |
253 } | 253 } |
254 | 254 |
255 }; | 255 }; |
256 | |
257 class ring_settings_test_suite : public CxxTest::TestSuite | |
258 { | |
259 public: | |
260 | |
261 void test_ring_settings() | |
262 { | |
263 enigma_machine machine({"Beta", "II", "IV", "I"}, {0, 2, 8, 21}, "B-Thin"); | |
264 | |
265 TS_ASSERT_EQUALS(machine.get_ring_setting(0), 0); | |
266 TS_ASSERT_EQUALS(machine.get_ring_setting(1), 2); | |
267 TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8); | |
268 TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21); | |
269 | |
270 std::vector<int> rings(machine.get_ring_settings()); | |
271 std::vector<int> expected{ 0, 2, 8, 21 }; | |
272 TS_ASSERT_EQUALS(rings, expected); | |
273 | |
274 machine.set_ring_setting(0, 25); | |
275 TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25); | |
276 TS_ASSERT_EQUALS(machine.get_ring_setting(1), 2); | |
277 TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8); | |
278 TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21); | |
279 | |
280 expected = { 25, 2, 8, 21 }; | |
281 TS_ASSERT_EQUALS(machine.get_ring_settings(), expected); | |
282 | |
283 machine.set_ring_setting(1, 18); | |
284 TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25); | |
285 TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18); | |
286 TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8); | |
287 TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21); | |
288 | |
289 expected = { 25, 18, 8, 21 }; | |
290 TS_ASSERT_EQUALS(machine.get_ring_settings(), expected); | |
291 | |
292 machine.set_ring_setting(2, 11); | |
293 TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25); | |
294 TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18); | |
295 TS_ASSERT_EQUALS(machine.get_ring_setting(2), 11); | |
296 TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21); | |
297 | |
298 expected = { 25, 18, 11, 21 }; | |
299 TS_ASSERT_EQUALS(machine.get_ring_settings(), expected); | |
300 | |
301 machine.set_ring_setting(3, 3); | |
302 TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25); | |
303 TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18); | |
304 TS_ASSERT_EQUALS(machine.get_ring_setting(2), 11); | |
305 TS_ASSERT_EQUALS(machine.get_ring_setting(3), 3); | |
306 | |
307 expected = { 25, 18, 11, 3 }; | |
308 TS_ASSERT_EQUALS(machine.get_ring_settings(), expected); | |
309 | |
310 expected = { 8, 9, 10, 11 }; | |
311 machine.set_ring_settings(expected); | |
312 TS_ASSERT_EQUALS(machine.get_ring_settings(), expected); | |
313 } | |
314 }; |