diff 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
line wrap: on
line diff
--- a/enigma/tests/test_machine.t.h	Wed Jul 04 19:52:41 2012 -0500
+++ b/enigma/tests/test_machine.t.h	Sat Jul 07 11:42:31 2012 -0500
@@ -253,3 +253,62 @@
    }
 
 };
+
+class ring_settings_test_suite : public CxxTest::TestSuite
+{
+public:
+
+   void test_ring_settings()
+   {
+      enigma_machine machine({"Beta", "II", "IV", "I"}, {0, 2, 8, 21}, "B-Thin");
+
+      TS_ASSERT_EQUALS(machine.get_ring_setting(0), 0);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(1), 2);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21);
+
+      std::vector<int> rings(machine.get_ring_settings());
+      std::vector<int> expected{ 0, 2, 8, 21 };
+      TS_ASSERT_EQUALS(rings, expected);
+
+      machine.set_ring_setting(0, 25);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(1), 2);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21);
+
+      expected = { 25, 2, 8, 21 };
+      TS_ASSERT_EQUALS(machine.get_ring_settings(), expected);
+
+      machine.set_ring_setting(1, 18);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(2), 8);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21);
+
+      expected = { 25, 18, 8, 21 };
+      TS_ASSERT_EQUALS(machine.get_ring_settings(), expected);
+
+      machine.set_ring_setting(2, 11);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(2), 11);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(3), 21);
+
+      expected = { 25, 18, 11, 21 };
+      TS_ASSERT_EQUALS(machine.get_ring_settings(), expected);
+
+      machine.set_ring_setting(3, 3);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(0), 25);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(1), 18);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(2), 11);
+      TS_ASSERT_EQUALS(machine.get_ring_setting(3), 3);
+
+      expected = { 25, 18, 11, 3 };
+      TS_ASSERT_EQUALS(machine.get_ring_settings(), expected);
+
+      expected = { 8, 9, 10, 11 };
+      machine.set_ring_settings(expected);
+      TS_ASSERT_EQUALS(machine.get_ring_settings(), expected);
+   }
+};