* Corrected small typos around resistor bands. * Due to failing CI, alterations to the test generator script were needed. The generated vs submitted diff now skips the first three lines of the file so that the generation date is not picked up and flagged as needing regeneration. Sadly, a workaround was also needed to prevent Python difflib from noting the difference anyways and producing an empty "false positive" diff. All templates and test files also needed to be altered to ensure that the first three lines of every test file will always be the autogeneration comment and date. Hopefully, this will now stop the CI failures without creating any subtle additional bugs. * Touch up to bowling template. Added back the error raising utility. * Touch up to two-bucket template to add back in error raising utility. [no important files changed]
69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
# These tests are auto-generated with test data from:
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/simple-cipher/canonical-data.json
|
|
# File last updated on 2023-07-20
|
|
|
|
import re
|
|
import unittest
|
|
|
|
from simple_cipher import (
|
|
Cipher,
|
|
)
|
|
|
|
|
|
class RandomKeyCipherTest(unittest.TestCase):
|
|
def test_can_encode(self):
|
|
cipher = Cipher()
|
|
plaintext = "aaaaaaaaaa"
|
|
self.assertEqual(cipher.encode(plaintext), cipher.key[0 : len(plaintext)])
|
|
|
|
def test_can_decode(self):
|
|
cipher = Cipher()
|
|
self.assertEqual(cipher.decode(cipher.key[0 : len("aaaaaaaaaa")]), "aaaaaaaaaa")
|
|
|
|
def test_is_reversible(self):
|
|
cipher = Cipher()
|
|
plaintext = "abcdefghij"
|
|
self.assertEqual(cipher.decode(cipher.encode(plaintext)), plaintext)
|
|
|
|
def test_key_is_made_only_of_lowercase_letters(self):
|
|
self.assertIsNotNone(re.match("^[a-z]+$", Cipher().key))
|
|
|
|
|
|
class SubstitutionCipherTest(unittest.TestCase):
|
|
def test_can_encode(self):
|
|
cipher = Cipher("abcdefghij")
|
|
plaintext = "aaaaaaaaaa"
|
|
self.assertEqual(cipher.encode(plaintext), cipher.key)
|
|
|
|
def test_can_decode(self):
|
|
cipher = Cipher("abcdefghij")
|
|
self.assertEqual(cipher.decode(cipher.key), "aaaaaaaaaa")
|
|
|
|
def test_is_reversible(self):
|
|
cipher = Cipher("abcdefghij")
|
|
plaintext = "abcdefghij"
|
|
self.assertEqual(cipher.decode(cipher.encode(plaintext)), plaintext)
|
|
|
|
def test_can_double_shift_encode(self):
|
|
cipher = Cipher("iamapandabear")
|
|
plaintext = "iamapandabear"
|
|
self.assertEqual(cipher.encode(plaintext), "qayaeaagaciai")
|
|
|
|
def test_can_wrap_on_encode(self):
|
|
cipher = Cipher("abcdefghij")
|
|
plaintext = "zzzzzzzzzz"
|
|
self.assertEqual(cipher.encode(plaintext), "zabcdefghi")
|
|
|
|
def test_can_wrap_on_decode(self):
|
|
cipher = Cipher("abcdefghij")
|
|
self.assertEqual(cipher.decode("zabcdefghi"), "zzzzzzzzzz")
|
|
|
|
def test_can_encode_messages_longer_than_the_key(self):
|
|
cipher = Cipher("abc")
|
|
plaintext = "iamapandabear"
|
|
self.assertEqual(cipher.encode(plaintext), "iboaqcnecbfcr")
|
|
|
|
def test_can_decode_messages_longer_than_the_key(self):
|
|
cipher = Cipher("abc")
|
|
self.assertEqual(cipher.decode("iboaqcnecbfcr"), "iamapandabear")
|