import unittest
-from rfc1751 import encode
+from rfc1751 import encode, decode
class TestRFC1751(unittest.TestCase):
+ def check(self, num: int, words: list[str]) -> None:
+ self.assertEqual(encode(num), words)
+ self.assertEqual(decode(words), num)
+
def testRFC1751(self) -> None:
- self.assertEqual(encode(0), ['A'])
- self.assertEqual(encode(1), ['ABE'])
- self.assertEqual(encode(2), ['ACE'])
- self.assertEqual(encode(2047), ['YOKE'])
- self.assertEqual(encode(2048), ['ABE', 'A'])
- self.assertEqual(encode(2049), ['ABE', 'ABE'])
- self.assertEqual(encode(2050), ['ABE', 'ACE'])
+ self.check(0, ['A'])
+ self.check(1, ['ABE'])
+ self.check(2, ['ACE'])
+ self.check(2047, ['YOKE'])
+ self.check(2048, ['ABE', 'A'])
+ self.check(2049, ['ABE', 'ABE'])
+ self.check(2050, ['ABE', 'ACE'])
# Note: These can get NSFW
- self.assertEqual(encode(2112325), ['FIRM', 'COCK'])
+ self.check(2112325, ['FIRM', 'COCK'])
if __name__ == '__main__':