'''
15-110 Homework 3
Name:
Andrew ID:
'''

import tkinter as tk

################################################################################

'''
#1 - addToAll(lst, x)
Parameters: list of numbers, numbers
Returns: None
'''

def addToAll(lst, x):
    return


'''
#2 - recursiveMax(lst)
Parameters: list of values
Returns: value
'''

def recursiveMax(lst):
    return


'''
#3 - generateBubbles(canvas, bubbleList)
Parameters: Tkinter canvas, list of dicts mapping strs to values
Returns: None
'''

def generateBubbles(canvas, bubbleList):
    return


'''
#4 - getBookByAuthor(bookInfo, author)
Parameters: dict mapping strs to strs, str
Returns: str
'''

def getBookByAuthor(bookInfo, author):
    return


'''
#5 - makeFirstPhonebook(nameList, numberList)
Parameters: list of strs, list of strs
Returns: dict mapping strs to strs
'''

def makeFirstPhonebook(nameList, numberList):
    return


################################################################################
''' Test Functions '''

def testAddToAll():
    print("Testing addToAll()...", end="")
    lst1 = [1, 2, 3]
    assert(addToAll(lst1, 2) == None) # addToAll is destructive- change the parameter instead of returning
    assert(lst1 == [3, 4, 5])

    lst2 = [5, 42, 300, 1, 75]
    assert(addToAll(lst2, 10) == None)
    assert(lst2 == [15, 52, 310, 11, 85])

    lst3 = [42]
    assert(addToAll(lst3, 110) == None)
    assert(lst3 == [152])

    lst4 = []
    assert(addToAll(lst4, 110) == None)
    assert(lst4 == [])
    print("... done!")

def testRecursiveMax():
    print("Testing recursiveMax()...", end="")
    assert(recursiveMax([1, 2, 3]) == 3)
    assert(recursiveMax([2, 4, 6, 9, 10, 2, 6]) == 10)
    assert(recursiveMax([4, 2, 10, 9, 20]) == 20)
    assert(recursiveMax([3, 4, 5]) == 5)
    assert(recursiveMax([4, 5, 1]) == 5)
    assert(recursiveMax([1,2,3,6,5,1]) == 6)
    assert(recursiveMax([67,5,3,7,9,23,45,0]) == 67)
    assert(recursiveMax(["dog","cat","bird","bear"]) == "dog")
    assert(recursiveMax(["dog","bird","elephant","bear"]) == "elephant")
    assert(recursiveMax(["mouse","cat","dog","fox"]) == "mouse")
    print("... done!")

def makeNBubbles(n):
    import random # we'll go over how this library works soon!
    bubbles = []
    for i in range(n):
        size = random.randint(1, 200)
        top = random.randint(0, 400 - size)
        left = random.randint(0, 400 - size)
        color = random.choice(["red", "orange", "yellow", "green", "blue", "purple", "pink"])
        bubbles.append({ "left" : left, "top" : top, "size" : size, "color" : color })
    return bubbles

def runGenerateBubbles():
    print("Testing generateBubbles()... check the screen!")
    root = tk.Tk()
    canvas = tk.Canvas(root, width=400, height=400)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    bubbleList1 = [ {"left" : 150, "top" : 150, "size" : 100, "color" : "green" } ]
    generateBubbles(canvas, bubbleList1)
    root.mainloop()

    root = tk.Tk()
    canvas = tk.Canvas(root, width=400, height=400)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    bubbleList2 = [
        {'left': 317, 'top': 269, 'size': 45, 'color': 'red'   },
        {'left': 118, 'top':  27, 'size': 90, 'color': 'orange'},
        {'left': 101, 'top': 321, 'size': 65, 'color': 'yellow'},
        {'left': 231, 'top': 219, 'size': 25, 'color': 'pink'  },
        {'left':  50, 'top':  12, 'size': 20, 'color': 'blue'  }]
    generateBubbles(canvas, bubbleList2)
    root.mainloop()

    root = tk.Tk()
    canvas = tk.Canvas(root, width=400, height=400)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    randomBubbles = makeNBubbles(10)
    generateBubbles(canvas, randomBubbles)
    root.mainloop()
    print("... generateBubbles() closed successfully.")

def testGetBookByAuthor():
    print("Testing getBookByAuthor()...", end="")
    assert(getBookByAuthor({ "The Hobbit" : "JRR Tolkein", "Harry Potter and the Sorcerer's Stone" : "JK Rowling", "A Game of Thrones" : "George RR Martin" }, "JK Rowling") == "Harry Potter and the Sorcerer's Stone")
    assert(getBookByAuthor({ "A Wrinkle in Time" : "Madeline L'Engle", "The Golden Compass" : "Phillip Pullman" }, "Madeline L'Engle") == "A Wrinkle in Time")
    assert(getBookByAuthor({ "The Chronicles of Chrestomanci" : "Diana Wynne Jones", "The Name of the Wind" : "Patrick Rothfuss", "Skyward" : "Brandon Sanderson", "The Fifth Season" : "N.K. Jemisin" }, "N.K. Jemisin") == "The Fifth Season")
    assert(getBookByAuthor({ "A Natural History of Dragons" : "Marie Brennan"}, "Marie Brennan") == "A Natural History of Dragons")
    assert(getBookByAuthor({ "The Chronicles of Chrestomanci" : "Diana Wynne Jones", "The Name of the Wind" : "Patrick Rothfuss", "Skyward" : "Brandon Sanderson", "The Fifth Season" : "N.K. Jemisin" }, "JRR Tolkein") == None)
    assert(getBookByAuthor({ }, "Brandon Sanderson") == None)
    print("... done!")

def testMakeFirstPhonebook():
    print("Testing makeFirstPhonebook()...", end="")
    assert(makeFirstPhonebook(["Kelly", "Dave", "Kelly"], ["0000", "1234", "9876"]) == { "Kelly" : "0000", "Dave" : "1234" })
    assert(makeFirstPhonebook(["Rebecca", "Ellie", "Gayatri", "Rishab"], ["5", "3", "7", "1"]) == { "Rebecca" : "5", "Ellie" : "3", "Gayatri" : "7", "Rishab" : "1" })
    assert(makeFirstPhonebook(["Stella", "Stella", "Stella"], ["1234", "5678", "9"]) == { "Stella" : "1234" })
    assert(makeFirstPhonebook(["CMU"], ["412-268-2000"]) == { "CMU" : "412-268-2000" })
    assert(makeFirstPhonebook(["A", "A", "B"], ["1", "2", "3"]) == { "A" : "1", "B" : "3" })
    assert(makeFirstPhonebook([ ], [ ]) == { })
    print("... done!")

def testAll():
    testAddToAll()
    testRecursiveMax()
    runGenerateBubbles()
    testGetBookByAuthor()
    testMakeFirstPhonebook()

testAll()