#################################################
# hw5.py
#################################################

def median(L):
    return 42

def checkKaladont(wordList):
    return 42

def upDownLeftRight(steps):
    return 42

######################################################################
# bonus/optional: you can ignore the functions below here
######################################################################

def histogram(a):
    return 42

def multiplyPolynomials(p1, p2):
    return 42

######################################################################
# ignore_rest: The autograder will ignore all code below here
######################################################################

#################################################
# Test Functions
#################################################

def almostEqual(d1, d2):
    epsilon = 10**-10
    return (abs(d2 - d1) < epsilon)

def testMedian():
    print('Testing median()...', end='')
    assert(median([ ]) == None)
    assert(median([ 42 ]) == 42)
    assert(almostEqual(median([ 1 ]), 1))
    assert(almostEqual(median([ 1, 2]), 1.5))
    assert(almostEqual(median([ 2, 3, 2, 4, 2]), 2))
    assert(almostEqual(median([ 2, 3, 2, 4, 2, 3]), 2.5))
    # now make sure this is non-destructive
    a = [ 2, 3, 2, 4, 2, 3]
    b = a + [ ]
    assert(almostEqual(median(b), 2.5))
    if (a != b):
        raise Exception('Your median() function should be non-destructive!')
    print('Passed')

def testCheckKaladont():
    print('Testing checkKaladont()...', end='')
    assert(checkKaladont(['cat', 'attic', 'icky']) == 'passed')
    assert(checkKaladont(['cat', 'attic', 'ICKY']) == 'passed')
    assert(checkKaladont(['cat', 'dog']) == 'mismatch')
    assert(checkKaladont(['cat', 'dog', '@#@!']) == 'mismatch')
    assert(checkKaladont(['cat', '@#@!', 'dog']) == 'non-alphabetic')
    assert(checkKaladont(['abc', 'bcab', 'abc']) == 'duplicateWord')
    assert(checkKaladont(['cat', 't']) == 'tooShortWord')
    assert(checkKaladont(['cat']) == 'tooShortList')
    a = ['cat', 'attic', 'icky']
    b = a + [ ]
    assert(checkKaladont(a) == 'passed')
    if (a != b):
        raise Exception('Your checkKaladont() function should be non-destructive!')
    print('Passed')

def testUpDownLeftRight():
    print('Testing upDownLeftRight()...', end='')
    assert(upDownLeftRight(['up 5', 'right 2']) == '2,5')
    assert(upDownLeftRight(['up 5', 'right 2', 'down']) == '2,4')
    assert(upDownLeftRight(['up 5', 'right 2', 'DOWN']) == '2,4')
    assert(upDownLeftRight(['up', 'right 2']) == '2,1')
    assert(upDownLeftRight(['up', 'RIGHT 2']) == '2,1')
    assert(upDownLeftRight(['up', 'WRONG! 2']) == 'illegal direction: WRONG!')
    assert(upDownLeftRight(['up', 'right ACK']) == 'illegal int: ACK')
    a = ['up 5', 'right 2']
    b = a + [ ]
    assert(upDownLeftRight(a) == '2,5')
    if (a != b):
        raise Exception('Your upDownLeftRight() function should be non-destructive!')
    print('Passed')

def testBonusHistogram():
    print("Testing bonus histogram()...", end="")
    assert(histogram([73, 62, 91, 74, 100, 77]) == """\
60-69: *
70-79: ***
80-89:
90++ : **
""")
    assert(histogram([100]) == """\
90++ : *
""")
    assert(histogram([5]) == """\
00-09: *
""")
    assert(histogram([5,10,15,20]) == """\
00-09: *
10-19: **
20-29: *
""")
    assert(histogram([0,1,2,3,39,40,49]) == """\
00-09: ****
10-19:
20-29:
30-39: *
40-49: **
""")
    assert(histogram([0, 100, 0, 100, 0]) == """\
00-09: ***
10-19:
20-29:
30-39:
40-49:
50-59:
60-69:
70-79:
80-89:
90++ : **
""")
    a = [5]
    b = a + [ ]
    assert(histogram(a) == """\
00-09: *
""")
    if (a != b):
        raise Exception('Your histogram() function should be non-destructive!')
    print("Passed!")

def testBonusMultiplyPolynomials():
    print('Testing bonus multiplyPolynomials()...', end='')
    # (2)*(3) == 6
    assert(multiplyPolynomials([2], [3]) == [6])
    # (2x-4)*(3x+5) == 6x^2 -2x - 20
    assert(multiplyPolynomials([2,-4],[3,5]) == [6,-2,-20])
    # (2x^2-4)*(3x^3+2x) == (6x^5-8x^3-8x)
    assert(multiplyPolynomials([2,0,-4],[3,0,2,0]) == [6,0,-8,0,-8,0])
    assert(multiplyPolynomials([1,3],[1,-3,9]) == [1,0,0,27])
    assert(multiplyPolynomials([2,-5],[4,10,25]) == [8,0,0,-125])
    a1 = [2]
    a2 = [3]
    b1 = a1 + []
    b2 = a2 + []
    assert(multiplyPolynomials(a1, a2) == [6])
    if ((a1 != b1) or (a2 != b2)):
        raise Exception('Your multiplyPolynomials() function should be non-destructive!')
    print('Passed!')

#################################################
# testAll and main
#################################################

def testAll():
    testMedian()
    testCheckKaladont()
    testUpDownLeftRight()
    # testBonusHistogram()
    # testBonusMultiplyPolynomials()

if __name__ == '__main__':
    testAll()
