#################################################
# 15-112-m18 hw4
# Your Name:
# Your Andrew ID:
# Your Section:
#################################################

import math
import string
import copy

#################################################
# Helper functions
#################################################

def almostEqual(d1, d2, epsilon=10**-7):
    return (abs(d2 - d1) < epsilon)

import decimal
def roundHalfUp(d):
    # Round to nearest with ties going away from zero.
    rounding = decimal.ROUND_HALF_UP
    # See other rounding options here:
    # https://docs.python.org/3/library/decimal.html#rounding-modes
    return int(decimal.Decimal(d).to_integral_value(rounding=rounding))

#################################################
# hw4 problems
#################################################

def lookAndSay(a):
    return 42

def nondestructiveRotateList(a, n):
    return 42

def destructiveRotateList(a, n):
    return 42

#################################################
# hw4 problems
# Note:
#   There are less test cases than usual here.
#   You'll want to add your own!
#################################################

def _verifyLookAndSayIsNondestructive():
    a = [1,2,3]
    b = copy.copy(a)
    lookAndSay(a) # ignore result, just checking for destructiveness here
    return (a == b)

def testLookAndSay():
    print("Testing lookAndSay()...", end="")
    assert(_verifyLookAndSayIsNondestructive() == True)
    assert(lookAndSay([]) == [])
    assert(lookAndSay([1,1,1]) ==  [(3,1)])
    print("Passed!")

def _verifynondestructiveRotateListIsNondestructive():
    a = [1,2,3]
    b = copy.copy(a)
    nondestructiveRotateList(a,1) # ignore result, just checking for destructiveness here
    return (a == b)

def testNondestructiveRotateList():
    print("Testing nondestructiveRotateList()...", end="")
    _verifynondestructiveRotateListIsNondestructive()
    assert(nondestructiveRotateList([1,2,3,4], 1) == [4,1,2,3])
    print("Passed!")

def testDestructiveRotateList():
    print("Testing destructiveRotateList()...", end="")

    # A single test case
    L = [1,2,3,4]
    r = destructiveRotateList(L,1)
    assert(r == None)
    assert(L == [4,1,2,3])

    print("Passed!")

#################################################
# hw4 Main
################################################

def testAll():
    testLookAndSay()
    testNondestructiveRotateList()
    testDestructiveRotateList()

def main():
    testAll()

if __name__ == '__main__':
    main()
