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

import math

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

#### consonantCount ####

def consonantCount(s):
    return 42


#### rotateStringLeft ####

def rotateStringLeft(s, n):
    return "42"

#### isRotation ####

def isRotation(s, t):
    return False


#### isFloat ####

def isFloat(s):
    return False

#### mostFrequentLetters ####


def mostFrequentLetters(s):
    return "42"


#### longestCommonSubstring ####

def longestCommonSubstring(s1, s2):
    return ""

#### BONUS/OPTIONAL: getEvalSteps ####

def getEvalSteps(expr):
    return ""

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

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


#### rotateStringLeft ####

def testRotateStringLeft():
    print('Testing rotateStringLeft()...', end='')
    assert(rotateStringLeft('abcde', 0) == 'abcde')
    assert(rotateStringLeft('abcde', 1) == 'bcdea')
    assert(rotateStringLeft('abcde', 2) == 'cdeab')
    assert(rotateStringLeft('abcde', 3) == 'deabc')
    assert(rotateStringLeft('abcde', 4) == 'eabcd')
    assert(rotateStringLeft('abcde', 5) == 'abcde')
    assert(rotateStringLeft('abcde', 25) == 'abcde')
    assert(rotateStringLeft('abcde', 28) == 'deabc')
    assert(rotateStringLeft('abcde', -1) == 'eabcd')
    assert(rotateStringLeft('abcde', -24) == 'bcdea')
    assert(rotateStringLeft('abcde', -25) == 'abcde')
    assert(rotateStringLeft('abcde', -26) == 'eabcd')
    print('Passed!')


#### 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!')


#### isFloat ###

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


#### mostFrequentLetters ####

def testMostFrequentLetters():
    print("Testing mostFrequentLetters()...", end="")

    s = "We attack at Dawn"
    result = "atwcdekn"
    assert(mostFrequentLetters(s) == result)

    s = "Note that digits, punctuation, and whitespace are not letters!"
    result = "teanioscdhpruglw"
    assert(mostFrequentLetters(s) == result)

    s = ""
    result = ""
    assert(mostFrequentLetters(s) == result)

    print("Passed!")


#### longestCommonSubstring ####

def testLongestCommonSubstring():
    print("Testing longestCommonSubstring()...", end="")
    assert(longestCommonSubstring("abcdef", "abqrcdest") == "cde")
    assert(longestCommonSubstring("abcdef", "ghi") == "")
    assert(longestCommonSubstring("", "abqrcdest") == "")
    assert(longestCommonSubstring("abcdef", "") == "")
    assert(longestCommonSubstring("abcABC", "zzabZZAB") == "AB")
    print("Passed!")


#### getEvalSteps ####

def testBonusGetEvalSteps():
    print("Testing getEvalSteps()...", end="")
    assert(getEvalSteps("3+2") == "3+2 = 5")
    assert(getEvalSteps("3-2") == 42)  # TODO: fill in 42
    assert(getEvalSteps("3**2") == "3**2 = 9")
    assert(getEvalSteps("31%16") == 42)  # TODO: fill in 42
    assert(getEvalSteps("31*16") == "31*16 = 496")
    assert(getEvalSteps("32//16") == "32//16 = 2")
    assert(getEvalSteps("2+3*4") == "2+3*4 = 2+12\n      = 14")
    assert(getEvalSteps("2*3+4") == 42
            )  # TODO: fill in 42 (hint: look at previous line!)
    assert(getEvalSteps("2+3*4-8**3%3") == """\
2+3*4-8**3%3 = 2+3*4-512%3
             = 2+12-512%3
             = 2+12-2
             = 14-2
             = 12""")
    assert(getEvalSteps("2+3**4%2**4+15//3-8") == """\
2+3**4%2**4+15//3-8 = 2+81%2**4+15//3-8
                    = 2+81%16+15//3-8
                    = 2+1+15//3-8
                    = 2+1+5-8
                    = 3+5-8
                    = 8-8
                    = 0""")
    print("Passed!")

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

def testAll():
    # comment out the tests you do not wish to run!
    testConsonantCount()
    testRotateStringLeft()
    testIsRotation()
    testIsFloat()
    testMostFrequentLetters()
    testLongestCommonSubstring()

    # Uncomment below to test the BONUS
    #testBonusGetEvalSteps()

def main():
    testAll()

if __name__ == '__main__':
    main()
