#################################################
# hw3.py
#
# Your name:
# Your andrew id:
#################################################

import math

#################################################
# Functions (for you to write)
#################################################

#### removeOdds ####

def removeOdds(L):
    return 42

#### maxProfit ####

def maxProfit(prices):
    return 42

#### nondestructiveRemoveRepeats ####

def nondestructiveRemoveRepeats(L):
    return [42]

#### destructiveRemoveRepeats ####

def destructiveRemoveRepeats(L):
    return None

#### averageWithPolicy ####

def averageWithPolicy(scores):
    return 42.0

#### isLegalSudoku ####

def isLegalSudoku(board):
    return True

def areLegalValues(a):
    return True

def isLegalRow(board, row):
    return True

def isLegalCol(board, col):
    return True

def isLegalBlock(board, block):
    return True


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

#### removeOdds ####

def testRemoveOdds():
    print("Testing removeOdds()...", end="")
    assert(removeOdds([1,3,4,3,6,2,1,7,5]) == [4,6,2])
    assert(removeOdds([1,2,3,-2]) == [2,-2])
    print("Passed.")

#### maxProfit ####

def testMaxProfit():
    print("Testing maxProfit()...", end="")
    print('Failed. This testcode needs to be written by you.')

#### nondestructiveRemoveRepeats ####

def testNondestructiveRemoveRepeats():
    print("Testing nondestructiveRemoveRepeats()...", end="")
    assert(nondestructiveRemoveRepeats([1,3,5,3,3,2,1,7,5]) == [1,3,5,2,7])
    assert(nondestructiveRemoveRepeats([1,2,3,-2]) == [1,2,3,-2])
    print("Passed.")

#### destructiveRemoveRepeats ####

def testDestructiveRemoveRepeats():
    print("Testing destructiveRemoveRepeats()...", end="")
    a = [1,3,5,3,3,2,1,7,5]
    assert(destructiveRemoveRepeats(a) == None)
    assert(a == [1,3,5,2,7])
    b = [1,2,3,-2]
    assert(destructiveRemoveRepeats(b) == None)
    assert(b == [1,2,3,-2])
    print("Passed.")

#### averageWithPolicy ####

def testAverageWithPolicy():
    print('Testing averageWithPolicy(scores)...', end='')
    assert(averageWithPolicy([42, 20, 40, 35, 50, 65]) == 47)
    assert(averageWithPolicy([25, 30, 20, 45, 40, 60, 70, 80, 90, 100]) == 59)
    assert(averageWithPolicy([40, 20]) == 30)
    assert(averageWithPolicy([40, 20, 10, 15, 9]) == 18.8)
    print('Passed!')

#### isLegalSudoku ####

def testAreLegalValues():
    print("Testing areLegalValues...", end="")
    assert(areLegalValues([]) == False)
    assert(areLegalValues([0]) == True)
    assert(areLegalValues([1]) == True)
    assert(areLegalValues([2]) == False)
    assert(areLegalValues([0, 1]) == False)
    assert(areLegalValues([0, 1, 2, 3]) == True)
    assert(areLegalValues([4, 1, 2, 3]) == True)
    assert(areLegalValues([0, 0, 2, 4]) == True)
    assert(areLegalValues([2, 1, 0, 2]) == False)
    assert(isNondestructive(areLegalValues, [0, 1, 2, 3]))
    print("Passed!")


def testIsLegalRow():
    print("Testing IsLegalRow...", end="")
    board0 = [
        [0, 2, 3, 4],
        [3, 0, 3, 1],
        [2, 1, 0, 0],
        [0, 0, 0, 0]
    ]
    assert(isLegalRow(board0, 0) == True)
    assert(isLegalRow(board0, 1) == False)
    print("Passed!")


def testIsLegalCol():
    print("Testing IsLegalCol...", end="")
    board0 = [
        [0, 2, 3, 4],
        [3, 0, 3, 1],
        [2, 1, 0, 0],
        [0, 0, 0, 0]
    ]
    assert(isLegalCol(board0, 0) == True)
    assert(isLegalCol(board0, 2) == False)
    print("Passed!")


def testIsLegalBlock():
    print("Testing IsLegalBlock...", end="")
    board1 = [
        [0, 2, 3, 4],
        [3, 0, 3, 1],
        [2, 1, 0, 4],
        [0, 0, 4, 0]
    ]
    assert(isLegalBlock(board1, 0) == True)
    assert(isLegalBlock(board1, 1) == False)
    assert(isLegalBlock(board1, 3) == False)
    print("Passed!")


def testIsLegalSudoku():
    testAreLegalValues()
    testIsLegalRow()
    testIsLegalCol()
    testIsLegalBlock()
    print("Testing isLegalSudoku...", end="")
    board0 = [
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0]
    ]
    assert(isLegalSudoku(board0) == True)
    board1 = [
        [1, 2, 3, 4],
        [4, 3, 2, 1],
        [2, 4, 1, 3],
        [3, 1, 4, 2]
    ]
    assert(isLegalSudoku(board1) == True)
    board2 = [
        [1, 2, 0, 4],
        [4, 0, 2, 0],
        [2, 0, 0, 3],
        [0, 1, 4, 0]
    ]
    assert(isLegalSudoku(board2) == True)
    board3 = [
        [1, 2, 1, 4],
        [4, 0, 2, 0],
        [2, 0, 0, 3],
        [0, 1, 4, 0]
    ]
    assert(isLegalSudoku(board3) == False)
    board4 = [
        [1, 2, 0, 4],
        [4, 0, 2, 3],
        [2, 0, 0, 3],
        [0, 1, 4, 0]
    ]
    assert(isLegalSudoku(board4) == False)
    board5 = [
        [1, 2, 0, 4],
        [4, 0, 2, 0],
        [2, 0, 0, 3],
        [0, 1, 3, 0]
    ]
    assert(isLegalSudoku(board5) == False)
    bigBoard = [
        [5, 3, 0, 0, 7, 0, 0, 0, 0],
        [6, 0, 0, 1, 9, 5, 0, 0, 0],
        [0, 9, 8, 0, 0, 0, 0, 6, 0],
        [8, 0, 0, 0, 6, 0, 0, 0, 3],
        [4, 0, 0, 8, 0, 3, 0, 0, 1],
        [7, 0, 0, 0, 2, 0, 0, 0, 6],
        [0, 6, 0, 0, 0, 0, 2, 8, 0],
        [0, 0, 0, 4, 1, 9, 0, 0, 5],
        [0, 0, 0, 0, 8, 0, 0, 7, 9]
    ]
    assert(isLegalSudoku(bigBoard) == True)
    print("Passed!")

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

def testAll():
    # comment out the tests you do not wish to run!
    testRemoveOdds()
    testMaxProfit()
    testNondestructiveRemoveRepeats()
    testDestructiveRemoveRepeats()
    testAverageWithPolicy()
    testIsLegalSudoku()


def main():
    testAll()

if __name__ == '__main__':
    main()
