Mercurial > public > enigma
changeset 20:abf2132ad338
Remove some unneeded conversions to string.
Corrected Wehrmacht to Heer in a variable name.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 27 May 2012 22:47:53 -0500 |
parents | d46635a9f088 |
children | ee1c84475eda |
files | enigma/plugboard.py enigma/tests/test_plugboard.py |
diffstat | 2 files changed, 8 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/enigma/plugboard.py Sun May 27 22:20:58 2012 -0500 +++ b/enigma/plugboard.py Sun May 27 22:47:53 2012 -0500 @@ -13,7 +13,7 @@ # On Heer & Luftwaffe (?) models, the plugs are labeled with upper case letters -WEHRMACHT_LABELS = string.ascii_uppercase +HEER_LABELS = string.ascii_uppercase # The number of plugboard cables supplied with a machine: MAX_PAIRS = 10 @@ -114,7 +114,7 @@ m, n = p.split('/') m, n = int(m), int(n) except ValueError: - raise PlugboardError('invalid pair: %s' % str(p)) + raise PlugboardError('invalid pair: %s' % p) wiring_pairs.append((m - 1, n - 1)) else: @@ -123,12 +123,12 @@ for p in pairs: if len(p) != 2: - raise PlugboardError('invalid pair: %s' % str(p)) + raise PlugboardError('invalid pair: %s' % p) m = p[0] n = p[1] - if m not in WEHRMACHT_LABELS or n not in WEHRMACHT_LABELS: - raise PlugboardError('invalid pair: %s' % str(p)) + if m not in HEER_LABELS or n not in HEER_LABELS: + raise PlugboardError('invalid pair: %s' % p) wiring_pairs.append((ord(m) - ord('A'), ord(n) - ord('A')))
--- a/enigma/tests/test_plugboard.py Sun May 27 22:20:58 2012 -0500 +++ b/enigma/tests/test_plugboard.py Sun May 27 22:47:53 2012 -0500 @@ -45,10 +45,12 @@ self.assertRaises(PlugboardError, Plugboard.from_key_sheet, '1*/26 17/4 21/6 3/16 19/14 22/3 8/1 12/25') self.assertRaises(PlugboardError, Plugboard.from_key_sheet, - '1*/26 17/4 2A/6 3/16 19/14 22/3 8/1 12/25') + '18/26 17/4 2A/6 3/16 19/14 22/3 8/1 12/25') self.assertRaises(PlugboardError, Plugboard.from_key_sheet, '100/2') self.assertRaises(PlugboardError, Plugboard.from_key_sheet, + '100') + self.assertRaises(PlugboardError, Plugboard.from_key_sheet, settings='T/C') def test_valid_settings(self):