2014-03-27 10:42:07 -03:00
|
|
|
import unittest
|
|
|
|
|
|
2014-04-20 19:32:08 +02:00
|
|
|
from atbash_cipher import decode, encode
|
|
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
|
2018-02-17 01:05:39 +08:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
|
2017-03-16 09:04:25 +01:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
class AtbashCipherTest(unittest.TestCase):
|
|
|
|
|
def test_encode_no(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode("no"), "ml")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_yes(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode("yes"), "bvh")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_OMG(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode("OMG"), "lnt")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_O_M_G(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode("O M G"), "lnt")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_long_word(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode("mindblowingly"), "nrmwy oldrm tob")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_numbers(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(
|
|
|
|
|
encode("Testing, 1 2 3, testing."), "gvhgr mt123 gvhgr mt")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_sentence(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(
|
|
|
|
|
encode("Truth is fiction."), "gifgs rhurx grlm")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
def test_encode_all_things(self):
|
|
|
|
|
plaintext = "The quick brown fox jumps over the lazy dog."
|
|
|
|
|
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(encode(plaintext), ciphertext)
|
2014-03-27 10:42:07 -03:00
|
|
|
|
|
|
|
|
def test_decode_word(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(decode("vcvix rhn"), "exercism")
|
2014-03-27 10:42:07 -03:00
|
|
|
|
|
|
|
|
def test_decode_sentence(self):
|
2015-11-22 11:37:13 +01:00
|
|
|
self.assertMultiLineEqual(
|
2017-03-23 13:37:20 +01:00
|
|
|
decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"),
|
|
|
|
|
"anobstacleisoftenasteppingstone")
|
2014-04-20 19:32:08 +02:00
|
|
|
|
2017-02-24 10:22:32 -04:00
|
|
|
def test_decode_numbers(self):
|
|
|
|
|
self.assertMultiLineEqual(
|
2017-03-23 13:37:20 +01:00
|
|
|
decode("gvhgr mt123 gvhgr mt"), "testing123testing")
|
2017-02-24 10:22:32 -04:00
|
|
|
|
2017-03-16 09:04:25 +01:00
|
|
|
def test_decode_all_the_letters(self):
|
|
|
|
|
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
|
|
|
|
|
plaintext = "thequickbrownfoxjumpsoverthelazydog"
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertMultiLineEqual(decode(ciphertext), plaintext)
|
2017-03-16 09:04:25 +01:00
|
|
|
|
|
|
|
|
# additional track specific test
|
2017-02-24 10:22:32 -04:00
|
|
|
def test_encode_decode(self):
|
|
|
|
|
self.assertMultiLineEqual(
|
2017-03-23 13:37:20 +01:00
|
|
|
decode(encode("Testing, 1 2 3, testing.")), "testing123testing")
|
2017-02-24 10:22:32 -04:00
|
|
|
|
2014-03-27 10:42:07 -03:00
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|