# Lillian Lee, LJL2, April 2021

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

import copy # for deepcopy, for making sure inputs aren't changed
import cornellasserts as ca


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

def sumfold(lst):
    pass




# some testing code
print("Checking sumfold")
testcases = [
    # format: (input, what list gets changed to)
    ([0, 1, 2, 3, 4], [0, 1, 3, 6, 10]),
    ([4, 3, 2, 1, 0], [4, 7, 9, 10, 10]),
    ([3], [3])
    ]

for item in testcases:
    inlist = item[0]    

    correct_change = item[1]
    error_msg_start = "sumfold problem " # prepare for any errors
    error_msg_start += "on input " + str(inlist) + ": "

    result = sumfold(inlist)
    
    # shouldn't return anything
    assert result is None, \
        error_msg_start + "should return None, but returned " + repr(result)

    # check values are correct
    assert inlist == correct_change, \
        error_msg_start + "expected the list to become " + repr(correct_change) \
        + " but it became/stayed " + repr(inlist)
print("Checking sumfold finished")

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

def zerocols(table):
    pass

# some testing code
print("Checking zerocols")
testcases = [
    # format: (input, return value)
    ([[1,0,2],[0,0,0],[3,0,4]], [1]),
    ([[0,0],[0,0]],  [0,1]),
    ([[1,0],[0,2]], [])
    ]

for item in testcases:
    table = item[0]
    origtable = copy.deepcopy(table) # copy to check that input was not changed
    expected = item[1]
    error_msg_start = "zerocols problem " # prepare for any errors
    error_msg_start += "on input " + str(table) + ": "

    result = zerocols(table)

    # check return
    assert result == expected, \
        error_msg_start + "expected output " + repr(expected) \
        + " but got " + repr(result)

    # check no change to input
    assert table == origtable, \
        error_msg_start + "changed input to " + repr(table)
print("Checking zerocols finished")

#######################
#### Q3(a)

def prefix(s):
    pass

# some testing code
print("Checking prefix")
testcases = [
    # format: (input, return value)
    ('abc', 1),
    ('xxxxxxyzx',  6),
    ('', 0),
    ('aab', 2)
    ]

for item in testcases:
    s = item[0]
    expected = item[1]
    error_msg_start = "prefix problem " # prepare for any errors
    error_msg_start += "on input " + str(s) + ": "

    result = prefix(s)
    assert result == expected, \
        error_msg_start + "expected output " + repr(expected) \
        + " but got " + repr(result)

print("Checking prefix finished")




#######################
#### Q3(b)

def invert(s):
    pass

# some testing code
print("Checking invert")
testanswers = {
    'hello': { 'h':[0], 'e':[1], 'l':[2,3], 'o':[4] },
    'abcac':  {'a':[0,3], 'b':[1], 'c':[2,4]},
    '': {}
}

for s in testanswers:
    error_msg_start = "invert problem " # prepare for any errors
    error_msg_start += "on input " + str(s) + ": " 
    result = invert(s)
    assert result == testanswers[s], \
        error_msg_start + "expected output " + repr(testanswers[s]) \
        + " but got " + repr(result)

print("Checking invert finished")

