You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/test_onetimepad.py

67 lines
2.6 KiB

import unittest
import onetimepad as OT
class TestOneTimePad(unittest.TestCase):
msg = ('HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFA'
'WOODCHUCKCOULDCHUCKWOOD' * 50)
_padsize = 2000
def test_mk_as_alpha_excludes_j(self):
self.assertTrue('J' not in OT._AS_ALPHA.values())
def test_mk_as_alpha_dict_has_25_members(self):
self.assertEqual(25, len(OT._AS_ALPHA.items()))
def test_creates_pad_of_desired_length(self):
for width in (72, 33, 99, 111):
pad = OT.create_pad(self._padsize, width=width)
lines = [line.strip('.') for line in pad.split()]
actual = len(''.join(lines))
self.assertEqual(self._padsize, len(''.join(lines)),
'pad of {0} chars created at width '
'{1}, actual={2}'.format(self._padsize,
width, actual))
def test_is_padline(self):
for lineno in PADLINES:
self.assertTrue(OT._is_padline(lineno),
'line {0} is padline'.format(lineno))
for lineno in TEXTLINES:
self.assertFalse(OT._is_padline(lineno),
'line {0} is not padline'.format(lineno))
for lineno in CIPHERLINES:
self.assertFalse(OT._is_padline(lineno),
'line {0} is not padline'.format(lineno))
def test_is_textline(self):
for lineno in TEXTLINES:
self.assertTrue(OT._is_textline(lineno),
'line {0} is textline'.format(lineno))
for lineno in PADLINES:
self.assertFalse(OT._is_textline(lineno),
'line {0} is not textline'.format(lineno))
for lineno in CIPHERLINES:
self.assertFalse(OT._is_textline(lineno),
'line {0} is not textline'.format(lineno))
def test_is_cipherline(self):
for lineno in CIPHERLINES:
self.assertTrue(OT._is_cipherline(lineno),
'line {0} is cipherline'.format(lineno))
for lineno in PADLINES:
self.assertFalse(OT._is_cipherline(lineno),
'line {0} is not cipherline'.format(lineno))
for lineno in TEXTLINES:
self.assertFalse(OT._is_cipherline(lineno),
'line {0} is not cipherline'.format(lineno))
PADLINES = (1, 4, 7, 10, 13, 16, 19, 22, 25)
TEXTLINES = (2, 5, 8, 11, 14, 17, 20, 23, 26)
CIPHERLINES = (3, 6, 9, 12, 15, 18, 21, 24, 27)
if __name__ == '__main__':
unittest.main()