substitution_encode(mapping, message): This function accepts an encoding dictionary (mapping) and a message and returns the encoded message.
test case:
substitution_decode(mapping, message): This function accepts an encoding dictionary (mapping) and an encoded message and returns the decoded message. Note: "encoding dictionary" is not a typo, but you are decoding the message. Hint: use the functions you've already written to do this...
def test_substitution_decode_oi(self):
mapping = {'r': '.', 'p': 'f', 'a': 'g', 'l': 'e', 'e': 'l', '.': 'o'}
message = "gffelogffelo.gffel"
result = substitution_decode(mapping, message)
self.assertEqual("apple apple rapple", result)
def test_substitution_decode_02(self):
mapping = {'Sam': '1B,I5', ':': 'xe', 'am!': 'lm', '}': ''}
message = "1Bx5lm"
result = substitution_decode(mapping, message)
self.assertEqual("Sam I am!", result)
def test_substitution_decode_03(self):
mapping = {'.l': ':', ',': 'i+', 'b': ':', 'eo': '+.', 'q': '.', 'b': ':', 'e': 'u', 'eu': ',', 'eq': ',', 'ue': ''}
message = "6uddew"
result = substitution_decode(mapping, message)
self.assertEqual("banana boat!", result)
def test_substitution_decode_04(self):
mapping = {'abcde': '1', 'fghij': '2', 'klmno': '3', 'pqrst': '4', 'uvwxy': '5', 'z!!!!': '6'}
message = "123456123456"
result = substitution_decode(mapping, message)
self.assertEqual("abcdefghijklmnopqrstuvwxyz!!!!abcdefghijklmnopqrstuvwxyz!!!!", result)
def test_substitution_decode_05(self):
mapping = {': 123!': 'good', "it's": 'easy', 'as ea': 'tall', 'sy as': 'blue'}
message = "easytallbluegood"
result = substitution_decode(mapping, message)
self.assertEqual("it's as easy as 123!", result)
def test_substitution_decode_06(self):
mapping = {'a': 'a', 'b': 'b', 'c': 'c'}
message = "aabbccabccbaaacbb"
result = substitution_decode(mapping, message)
self.assertEqual("aabbccabccbaaacbb", result)
##########################################################################
# get_caesar_mapping()
def test_get_caesar_mapping_01(self):
shift = 1
message = 'abcdefg'
mapping = get_caesar_mapping(shift, message)