2014-06-11 15:06:22 +02:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from crypto_square import (
|
|
|
|
|
cipher_text,
|
|
|
|
|
)
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2023-07-14 15:52:15 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/crypto-square/canonical-data.json
|
|
|
|
|
# File last updated on 2023-07-14
|
2017-10-30 14:57:53 -02:00
|
|
|
|
2019-10-03 22:47:06 +03:00
|
|
|
|
2014-04-09 14:20:52 -03:00
|
|
|
class CryptoSquareTest(unittest.TestCase):
|
2019-10-03 22:47:06 +03:00
|
|
|
def test_empty_plaintext_results_in_an_empty_ciphertext(self):
|
|
|
|
|
value = ""
|
|
|
|
|
expected = ""
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2022-12-02 18:44:15 +01:00
|
|
|
def test_normalization_results_in_empty_plaintext(self):
|
|
|
|
|
value = "... --- ..."
|
|
|
|
|
expected = ""
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
|
|
|
|
|
2017-10-30 14:57:53 -02:00
|
|
|
def test_lowercase(self):
|
2019-10-03 22:47:06 +03:00
|
|
|
value = "A"
|
|
|
|
|
expected = "a"
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
2017-10-30 14:57:53 -02:00
|
|
|
|
|
|
|
|
def test_remove_spaces(self):
|
2019-10-03 22:47:06 +03:00
|
|
|
value = " b "
|
|
|
|
|
expected = "b"
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
2017-10-30 14:57:53 -02:00
|
|
|
|
|
|
|
|
def test_remove_punctuation(self):
|
2019-10-03 22:47:06 +03:00
|
|
|
value = "@1,%!"
|
|
|
|
|
expected = "1"
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
|
|
|
|
|
|
|
|
|
def test_9_character_plaintext_results_in_3_chunks_of_3_characters(self):
|
|
|
|
|
value = "This is fun!"
|
|
|
|
|
expected = "tsf hiu isn"
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
|
|
|
|
|
|
|
|
|
def test_8_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 22:47:06 +03:00
|
|
|
):
|
|
|
|
|
value = "Chill out."
|
|
|
|
|
expected = "clu hlt io "
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|
|
|
|
|
|
|
|
|
|
def test_54_character_plaintext_results_in_7_chunks_the_last_two_with_trailing_spaces(
|
2021-01-31 16:49:12 -05:00
|
|
|
self,
|
2019-10-03 22:47:06 +03:00
|
|
|
):
|
|
|
|
|
value = "If man was meant to stay on the ground, god would have given us roots."
|
|
|
|
|
expected = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau "
|
|
|
|
|
self.assertEqual(cipher_text(value), expected)
|