2014-06-11 15:06:22 +02:00
|
|
|
import unittest
|
|
|
|
|
|
2014-10-19 20:56:54 +02:00
|
|
|
from crypto_square import encode
|
2014-04-09 14:20:52 -03:00
|
|
|
|
|
|
|
|
|
2018-02-17 03:54:32 +08:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v3.2.0
|
2017-10-30 14:57:53 -02:00
|
|
|
|
2014-04-09 14:20:52 -03:00
|
|
|
class CryptoSquareTest(unittest.TestCase):
|
2014-10-19 20:56:54 +02:00
|
|
|
def test_empty_string(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(encode(''), '')
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2017-10-30 14:57:53 -02:00
|
|
|
def test_lowercase(self):
|
|
|
|
|
self.assertEqual(encode('A'), 'a')
|
|
|
|
|
|
|
|
|
|
def test_remove_spaces(self):
|
|
|
|
|
self.assertEqual(encode(' b '), 'b')
|
|
|
|
|
|
|
|
|
|
def test_remove_punctuation(self):
|
|
|
|
|
self.assertEqual(encode('@1,%!'), '1')
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2017-10-30 14:57:53 -02:00
|
|
|
def test_9chars_results_3chunks(self):
|
|
|
|
|
self.assertEqual(encode('This is fun!'), 'tsf hiu isn')
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2017-10-30 14:57:53 -02:00
|
|
|
def test_8chars_results_3chunks_ending_space(self):
|
|
|
|
|
self.assertEqual(encode('Chill out.'), 'clu hlt io ')
|
2014-04-09 14:20:52 -03:00
|
|
|
|
2017-10-30 14:57:53 -02:00
|
|
|
def test_54chars_results_7chunks_2ending_space(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
encode('If man was meant to stay on the ground, '
|
|
|
|
|
'god would have given us roots.'),
|
|
|
|
|
'imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau '
|
|
|
|
|
)
|
2014-04-09 14:20:52 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|