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

import tkinter as tk

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

'''
#1 - onlyPositive(lst)
Parameters: 2D list of numbers
Returns: list of numbers
'''

def onlyPositive(lst):
    return


'''
#2 - getCharacterLines(script, character)
Parameters: str, str
Returns: list of strings
'''
def getCharacterLines(script, character):
    return


'''
#3 - addToEach(lst, str)
Parameters: list of string, string
Returns: None
'''

def addToEach(lst, str):
    return



'''
#4 - recursiveLongestString(lst)
Parameters: list of strings
Returns: str
'''

def recursiveLongestString(lst):
    return


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

def generateBubbles(canvas, bubbleList):
    return


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

def getBookByAuthor(bookInfo, author):
    return



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

def testOnlyPositive():
    print("Testing onlyPositive()...", end="")
    assert(onlyPositive([[1, 2, 3], [4, 5, 6]]) == [1, 2, 3, 4, 5, 6])
    assert(onlyPositive([[0, 1, 2], [-2, -1, 0], [10, 9, -9]]) == [1, 2, 10, 9])
    assert(onlyPositive([[-4, -3], [-2, -1]]) == [ ])
    assert(onlyPositive([[3, 4, 5]]) == [3, 4, 5])
    assert(onlyPositive([[-4], [3], [5]]) == [3, 5])
    assert(onlyPositive([[-1, 2], [-3, 4], [-5, 6]]) == [2, 4, 6])
    assert(onlyPositive([[1, 5, -3, 7, 9, -23, -45, 67]]) == [1, 5, 7, 9, 67])
    assert(onlyPositive([[-5], [-4], [-3], [-2], [-1]]) == [ ])
    assert(onlyPositive([ [0], [0] ]) == [ ])
    print("... done!")

def testGetCharacterLines():
    print("Testing getCharacterLines()...", end="")
    s1 = '''
Buttercup: You mock my pain.
Man in Black: Life is pain, Highness.
Man in Black: Anyone who says differently is selling something.
'''.strip()
    assert(getCharacterLines(s1, "Buttercup") == [ "You mock my pain." ])
    assert(getCharacterLines(s1, "Man in Black") == [ "Life is pain, Highness.",
        "Anyone who says differently is selling something." ])
    assert(getCharacterLines(s1, "Inigo Montoya") == [ ])

    s2 = '''
Burr: Can I buy you a drink?
Hamilton: That would be nice.
Burr: While we're talking, let me offer you some free advice: talk less.
Hamilton: What?
Burr: Smile more.
Hamilton: Ha.
Burr: Don't let them know what you're against or what you're for.
Hamilton: You can't be serious.
Burr: You want to get ahead?
Hamilton: Yes.
Burr: Fools who run their mouths oft wind up dead.
'''.strip()
    assert(getCharacterLines(s2, "Hamilton") == [ "That would be nice.",
        "What?", "Ha.", "You can't be serious.", "Yes." ])
    assert(getCharacterLines(s2, "Burr") == [ "Can I buy you a drink?",
        "While we're talking, let me offer you some free advice: talk less.", "Smile more.", "Don't let them know what you're against or what you're for.", "You want to get ahead?", "Fools who run their mouths oft wind up dead." ])

    s3 = '''
Luke: Look at him. He's headed for that small moon.
Han: I think I can get him before he gets there... he's almost in range.
Ben: That's no moon! It's a space station.
Han: It's too big to be a space station.
Luke: I have a very bad feeling about this.
'''.strip()
    assert(getCharacterLines(s3, "Luke") == [ "Look at him. He's headed for that small moon.", "I have a very bad feeling about this." ])
    assert(getCharacterLines(s3, "Han") == [ "I think I can get him before he gets there... he's almost in range.", "It's too big to be a space station." ])
    assert(getCharacterLines(s3, "Ben") == [ "That's no moon! It's a space station." ])

    s4 = '''
Threepio: Did you hear that? They've shut down the main reactor. We'll be destroyed for sure. This is madness!
Threepio: We're doomed!
Threepio: There'll be no escape for the Princess this time.
Threepio: What's that?
'''.strip()
    assert(getCharacterLines(s4, "Threepio") == [ "Did you hear that? They've shut down the main reactor. We'll be destroyed for sure. This is madness!", "We're doomed!", "There'll be no escape for the Princess this time.", "What's that?"])
    print("... done!")

def testAddToEach():
    print("Testing addToEach()...", end="")
    lst1 = ["1", "2", "3"]
    assert(addToEach(lst1, "2") == None) # addToEach is destructive- change the parameter instead of returning
    assert(lst1 == ["12", "22", "32"])

    lst2 = ["a", "bc", "dee", "f", "gh"]
    assert(addToEach(lst2, "qr") == None)
    assert(lst2 == ["aqr", "bcqr", "deeqr", "fqr", "ghqr"])

    lst3 = ["zf"]
    assert(addToEach(lst3, "abc") == None)
    assert(lst3 == ["zfabc"])

    lst4 = []
    assert(addToEach(lst4, "lol") == None)
    assert(lst4 == [])
    print("... done!")

def testRecursiveLongestString():
    print("Testing recursiveLongestString()...", end="")
    assert(recursiveLongestString(["a", "bb", "ccc"]) == "ccc")
    assert(recursiveLongestString(["hi", "its", "fantastic", "here"]) == "fantastic")
    assert(recursiveLongestString(["tremendously", "excited", "for", "today"]) == "tremendously")
    assert(recursiveLongestString(["Carnegie", "Mellon", "University"]) == "University")
    assert(recursiveLongestString(["when", "you", "wish", "upon", "a", "star", "doesn't", "matter", "who", "you", "are"]) == "doesn't")
    assert(recursiveLongestString(["computer", "science"]) == "computer")
    assert(recursiveLongestString(["python", "program"]) == "program")
    assert(recursiveLongestString(["programming"]) == "programming")
    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 testAll():
    testOnlyPositive()
    testGetCharacterLines()
    testAddToEach()
    testRecursiveLongestString()
    runGenerateBubbles()
    testGetBookByAuthor()

testAll()