# Lillian Lee, LJL2, April 2021

"""Quick and dirty code for 2018FA prelim 2 questions."""

import copy # for checking no change in input

##################
# Q2(a)

def encode(cipher, text):
    pass

# some testing code
print("Checking encode")

testcases = [
    ({'a':'o','b':'z'},  'bat', 'zot'),
    ({'a':'o','z':'b'}, 'razzle', 'robble'),
    ({'a':'o','z':'b'}, '', '')
]

for item in testcases:
    cipher = item[0]
    text = item[1]
    expected = item[2]
    orig_cipher = dict(cipher)
    error_msg_start = "encode problem " # prepare for any errors
    error_msg_start += "on input " + str((str(cipher), text)) + ": "

    result = encode(cipher, text)
    
    # changed cipher
    assert cipher == orig_cipher, \
        error_msg_start + "input cipher was changed! It's now " + repr(cipher)

    # check values are correct
    assert result == expected, \
        error_msg_start + "expected " + repr(expected) \
        + " but got " + repr(result)

print("Checking encode finished")

##################
# Q2(b)

def invert(cipher):
    pass


testcases = [
     ({'a':'o','z':'b'}, {'o': 'a', 'b': 'z'})
]

# some testing code
print("Checking invert")
for item in testcases:
    cipher = item[0]; 
    expected = item[1];  
    error_msg_start = "invert problem " # prepare for any errors
    error_msg_start += "on input " + str((str(cipher), text)) + ": "

    result = invert(cipher)

    assert result is None, error_msg_start + "should return None, but returned " + str(result)
    assert cipher == expected, error_msg_start + "expected " + str(expected) \
                                + " but got " + str(cipher)
print("Checking invert finished")
##################
# Q3(a)

def decode(nlist):
    pass
    

# some testing code
print("Checking decode")

testcases = [
    ([['a',3],['h',1],['a',1]], 'aaaha'),
    ([], '')
]

for item in testcases:
    nlist = item[0]
    expected = item[1]
    orig_list = nlist[:]

    error_msg_start = "decode problem " # prepare for any errors
    error_msg_start += "on input " + str(nlist) + ": "

    result = decode(nlist)
    assert orig_list == nlist, "input list was changed to " + str(nlist)
    assert result == expected, "expected " + str(expected) + " but got " + str(result)


print("Checking decode finished")

##################
# Q3(b)
def encode(text):
    pass
# some testing code
print("Checking second encode")
testcases = {
    'aaaha': [['a',3],['h',1],['a',1]],
    '': []
}

for text in testcases:
    expected = testcases[text]
    error_msg_start = "second encode problem " # prepare for any errors
    error_msg_start += "on input " + str(nlist) + ": "

    result = encode(text)
    assert result == expected, "expected " + str(expected) + " but got " + str(result)




print("Checking second encode finished")
