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

import math

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

#### isRotation ####

def isRotation(s, t):
    return False


#### applyCaesarCipher ####

def applyCaesarCipher(s, cnt):
    return "42"


#### topScorer ####

def topScorer(data):
    return "42"


#### mostFrequentSubstring ####

def mostFrequentSubstring(text, n):
    return "42"


#### patternedMessage ####

def patternedMessage(msg, pattern):
    return "42"


#### bestScrabbleScore ####

def bestScrabbleScore(dictionary, letterScores, hand):
    return (["42"], 42)


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

#### isRotation ####

def testIsRotation():
    print('Testing isRotation()...', end='')
    assert(isRotation('a', 'a') == False) # a string is not a rotation of itself
    assert(isRotation('', '') == False) # a string is not a rotation of itself
    assert(isRotation('ab', 'ba') == True)
    assert(isRotation('abcd', 'dabc') == True)
    assert(isRotation('abcd', 'cdab') == True)
    assert(isRotation('abcd', 'bcda') == True)
    assert(isRotation('abcd', 'abcd') == False)
    assert(isRotation('abcd', 'bcd') == False)
    assert(isRotation('abcd', 'bcdx') == False)
    print('Passed!')

#### applyCaesarCipher ####

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


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


#### mostFrequentSubstring ####

def testMostFrequentSubstring():
    print("Testing mostFrequentSubstring()...", end="")
    assert(mostFrequentSubstring("baababacb", 3) == "aba")
    assert(mostFrequentSubstring("thequickbrownfoxjumpsoverthelazydog", 1) == "o")
    assert(mostFrequentSubstring("testingthecodetofindtheerrortestandtestagain", 4) == "test")
    print("Passed!")


#### patternedMessage ####

def testPatternedMessage():
    print("Testing patternedMessage()...", end="")
    parms = [
        ("Go Pirates!!!", """
***************
******   ******
***************
"""),
        ("Three Diamonds!", """
    *     *     *
   ***   ***   ***
  ***** ***** *****
   ***   ***   ***
    *     *     *
"""),
        ("Go Steelers!", """
                          oooo$$$$$$$$$$$$oooo
                      oo$$$$$$$$$$$$$$$$$$$$$$$$o
                   oo$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o         o$   $$ o$
   o $ oo        o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o       $$ $$ $$o$
oo $ $ '$      o$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$o       $$$o$$o$
'$$$$$$o$     o$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$o    $$$$$$$$
  $$$$$$$    $$$$$$$$$$$      $$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$$$$$$$    $$$$$$$$$$$$$    $$$$$$$$$$$$$$  '$$$
   '$$$'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     '$$$
    $$$   o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     '$$$o
   o$$'   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$       $$$o
   $$$    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' '$$$$$$ooooo$$$$o
  o$$$oooo$$$$$  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$   o$$$$$$$$$$$$$$$$$
  $$$$$$$$'$$$$   $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$     $$$$'
 ''''       $$$$    '$$$$$$$$$$$$$$$$$$$$$$$$$$$$'      o$$$
            '$$$o     '$$$$$$$$$$$$$$$$$$'$$'         $$$
              $$$o          '$$'$$$$$$'           o$$$
               $$$$o                                o$$$'
                '$$$$o      o$$$$$$o'$$$$o        o$$$$
                  '$$$$$oo     '$$$$o$$$$$o   o$$$$'
                     '$$$$$oooo  '$$$o$$$$$$$$$'
                        '$$$$$$$oo $$$$$$$$$$
                                '$$$$$$$$$$$
                                    $$$$$$$$$$$$
                                     $$$$$$$$$$'
                                      '$$$'
""")]
    solns = [
        """
GoPirates!!!GoP
irates   !!!GoP
irates!!!GoPira
""",
        """
    T     h     r
   eeD   iam   ond
  s!Thr eeDia monds
   !Th   ree   Dia
    m     o     n
""",
        """
                          GoSteelers!GoSteeler
                      s!GoSteelers!GoSteelers!GoS
                   teelers!GoSteelers!GoSteelers!GoS         te   el er
   s ! Go        Steelers!GoSteelers!GoSteelers!GoSteel       er s! GoSt
ee l e rs      !GoSteeler    s!GoSteelers!    GoSteelers       !GoSteel
ers!GoSte     elers!GoSt      eelers!GoSt      eelers!GoSt    eelers!G
  oSteele    rs!GoSteele      rs!GoSteele      rs!GoSteelers!GoSteeler
  s!GoSteelers!GoSteelers    !GoSteelers!G    oSteelers!GoSt  eele
   rs!GoSteelers!GoSteelers!GoSteelers!GoSteelers!GoSteel     ers!
    GoS   teelers!GoSteelers!GoSteelers!GoSteelers!GoSteelers     !GoSt
   eele   rs!GoSteelers!GoSteelers!GoSteelers!GoSteelers!GoSt       eele
   rs!    GoSteelers!GoSteelers!GoSteelers!GoSteelers!Go Steelers!GoSteele
  rs!GoSteelers  !GoSteelers!GoSteelers!GoSteelers!GoS   teelers!GoSteelers
  !GoSteelers!G   oSteelers!GoSteelers!GoSteelers!Go     Steel
 ers!       GoSt    eelers!GoSteelers!GoSteelers!G      oSte
            elers     !GoSteelers!GoSteelers!         GoS
              teel          ers!GoSteel           ers!
               GoSte                                elers
                !GoSte      elers!GoSteele        rs!Go
                  Steelers     !GoSteelers!   GoStee
                     lers!GoSte  elers!GoSteeler
                        s!GoSteele rs!GoSteel
                                ers!GoSteele
                                    rs!GoSteeler
                                     s!GoSteeler
                                      s!GoS
"""
    ]
    parms = [("A-C D?", """
*** *** ***
** ** ** **
"""),
             ("A", "x y z"),
             ("The pattern is empty!", "")
             ]
    solns = [
        """
A-C D?A -CD
?A -C D? A-
""",
        "A A A",
        ""
    ]
    for i in range(len(parms)):
        msg, pattern = parms[i]
        soln = solns[i]
        soln = soln.strip("\n")
        observed = patternedMessage(msg, pattern)
        assert(observed == soln)
    print("Passed!")


#### bestScrabbleScore ####

def testBestScrabbleScore():
    print("Testing bestScrabbleScore()...", end="")
    def dictionary1(): return ["a", "b", "c"]
    def letterScores1(): return [1] * 26
    def dictionary2(): return ["xyz", "zxy", "zzy", "yy", "yx", "wow"]
    def letterScores2(): return [1 + (i % 5) for i in range(26)]
    assert(bestScrabbleScore(
            dictionary1(),
            letterScores1(),
            ["a", "c", "e"]) == (["a", "c"], 1))
    assert(bestScrabbleScore(
           dictionary1(),
           letterScores1(),
           ["b"]) == ("b", 1))
    assert(
        bestScrabbleScore(
            dictionary1(),
            letterScores1(),
            ["z"]) is None)
    assert(bestScrabbleScore(
            dictionary2(),
            letterScores2(),
            ["x", "y", "z"]) == (["xyz", "zxy"], 10))
    assert(bestScrabbleScore(
            dictionary2(),
            letterScores2(),
            ["x", "y", "z", "y"]) == (["xyz", "zxy", "yy"], 10))
    assert(bestScrabbleScore(
            dictionary2(),
            letterScores2(),
            ["x", "y", "q"]) == ("yx", 9))
    assert(bestScrabbleScore(
            dictionary2(),
            letterScores2(),
            ["y", "z", "z"]) == ("zzy", 7))
    assert(
        bestScrabbleScore(
            dictionary2(),
            letterScores2(),
            ["w", "x", "z"]) is None)
    print("Passed!")


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

def testAll():
    # comment out the tests you do not wish to run!
    testIsRotation()
    testApplyCaesarCipher()
    testTopScorer()
    testMostFrequentSubstring()
    testPatternedMessage()
    testBestScrabbleScore()


def main():
    testAll()

if __name__ == '__main__':
    main()
