Mercurial > public > m209
changeset 11:45af97a43ee1
Gave KeyWheel a __str__() method and test.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 04 Jun 2013 19:31:37 -0500 |
parents | 1e1c4b41135d |
children | 778f0bd51818 |
files | m209/key_wheel.py m209/tests/test_key_wheel.py |
diffstat | 2 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/m209/key_wheel.py Tue Jun 04 18:49:12 2013 -0500 +++ b/m209/key_wheel.py Tue Jun 04 19:31:37 2013 -0500 @@ -50,6 +50,15 @@ # rotational position; 0 means first letter shown to operator self.pos = 0 + def __str__(self): + parts = [] + for n, c in enumerate(self.letters): + if self.pins[n]: + parts.append(c + '-') + else: + parts.append('-' + c) + return ' '.join(parts) + def reset_pins(self): """Reset all pins to the ineffective state.""" self.pins = [False] * self.num_pins
--- a/m209/tests/test_key_wheel.py Tue Jun 04 18:49:12 2013 -0500 +++ b/m209/tests/test_key_wheel.py Tue Jun 04 19:31:37 2013 -0500 @@ -105,3 +105,8 @@ for c in letters: kw.set_pos(c) self.assertEqual(c, kw.display()) + + def test_str(self): + kw = KeyWheel(string.ascii_uppercase, 'P', 'FGIKOPRSUVWYZ') + self.assertEqual(str(kw), ('-A -B -C -D -E F- G- -H I- -J K- -L -M -N ' + 'O- P- -Q R- S- -T U- V- W- -X Y- Z-'))