2017-04-03 10:48:11 -03:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from rotational_cipher import (
|
|
|
|
|
rotate,
|
|
|
|
|
)
|
2017-04-03 10:48:11 -03:00
|
|
|
|
2020-10-15 12:46:24 -04:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json`
|
2017-04-05 11:36:23 +02:00
|
|
|
|
2019-10-06 07:52:07 +05:30
|
|
|
|
2018-06-13 09:12:09 -04:00
|
|
|
class RotationalCipherTest(unittest.TestCase):
|
2019-10-06 07:52:07 +05:30
|
|
|
def test_rotate_a_by_0_same_output_as_input(self):
|
|
|
|
|
self.assertEqual(rotate("a", 0), "a")
|
2017-10-25 14:36:29 +02:00
|
|
|
|
2017-04-03 10:48:11 -03:00
|
|
|
def test_rotate_a_by_1(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("a", 1), "b")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
2019-10-06 07:52:07 +05:30
|
|
|
def test_rotate_a_by_26_same_output_as_input(self):
|
|
|
|
|
self.assertEqual(rotate("a", 26), "a")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_m_by_13(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("m", 13), "z")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_n_by_13_with_wrap_around_alphabet(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("n", 13), "a")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_capital_letters(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("OMG", 5), "TRL")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_spaces(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("O M G", 5), "T R L")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_numbers(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("Testing 1 2 3 testing", 4), "Xiwxmrk 1 2 3 xiwxmrk")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_punctuation(self):
|
2019-10-06 07:52:07 +05:30
|
|
|
self.assertEqual(rotate("Let's eat, Grandma!", 21), "Gzo'n zvo, Bmviyhv!")
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
def test_rotate_all_letters(self):
|
|
|
|
|
self.assertEqual(
|
2019-10-06 07:52:07 +05:30
|
|
|
rotate("The quick brown fox jumps over the lazy dog.", 13),
|
|
|
|
|
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.",
|
|
|
|
|
)
|
2017-04-03 10:48:11 -03:00
|
|
|
|
|
|
|
|
|
2019-10-06 07:52:07 +05:30
|
|
|
if __name__ == "__main__":
|
2017-04-03 10:48:11 -03:00
|
|
|
unittest.main()
|