changeset 3:345154208fb6

The wiring test now tests all ring settings, rotations, and positions.
author Brian Neal <bgneal@gmail.com>
date Sat, 26 May 2012 00:38:36 -0500
parents 81665fcaa36d
children de413df1c9c5
files enigma/tests/test_rotor.py
diffstat 1 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/enigma/tests/test_rotor.py	Sat May 26 00:09:17 2012 -0500
+++ b/enigma/tests/test_rotor.py	Sat May 26 00:38:36 2012 -0500
@@ -66,19 +66,21 @@
                 self.assertEqual(s, rotor.get_display())
 
     def test_wiring(self):
-        rotor = Rotor('I', WIRING, ring_setting=0, alpha_labels=True)
 
-        for n, d in enumerate(ALPHA_LABELS):
-            rotor.set_display(d)
+        for r in range(26):
+            rotor = Rotor('I', WIRING, ring_setting=r, alpha_labels=True)
 
-            wiring = collections.deque(WIRING)
-            wiring.rotate(-n)
+            for n, d in enumerate(ALPHA_LABELS):
+                rotor.set_display(d)
 
-            for i in range(26):
-                output = rotor.signal_in(i)
+                wiring = collections.deque(WIRING)
+                wiring.rotate(r - n)
 
-                expected = (ord(wiring[i]) - ord('A') - n) % 26
-                self.assertEqual(output, expected)
+                for i in range(26):
+                    output = rotor.signal_in(i)
 
-                output = rotor.signal_out(expected)
-                self.assertEqual(output, i)
+                    expected = (ord(wiring[i]) - ord('A') + r - n) % 26
+                    self.assertEqual(output, expected)
+
+                    output = rotor.signal_out(expected)
+                    self.assertEqual(output, i)