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

import cs112_m20_day5_linter
import copy

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

def almostEqual(d1, d2, epsilon=10**-7):
    # note: use math.isclose() outside 15-112 with Python version 3.5 or later
    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))

#################################################
# Functions for you to write
#################################################

def lookAndSay(L):
    return 42

def inverseLookAndSay(L):
    return 42

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

def isNondestructive(f,L): # Checks to make sure f(L) does not modify L
    unmodifiedCopy = copy.deepcopy(L)
    b = f(L)
    return L == unmodifiedCopy

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

def testInverseLookAndSay():
    print("Testing inverseLookAndSay()...", end="")
    assert(inverseLookAndSay([]) == [])
    assert(inverseLookAndSay([(1,1)]) == [1])
    assert(inverseLookAndSay([(3,1)]) == [1,1,1])
    assert(
        inverseLookAndSay([(1,1),(2,2),(3,3),(4,4)]) == [1,2,2,3,3,3,4,4,4,4]
    )
    assert(isNondestructive(inverseLookAndSay,[(3,1)]))
    assert(isNondestructive(inverseLookAndSay,[(2,1),(1,2),(1,1),(2,2)]))
    assert(isNondestructive(inverseLookAndSay,[(1,1),(2,2),(3,3),(4,4)]))
    print("Passed!")

#################################################
# collab4 Main
################################################

def testAll():
    testLookAndSay()
    testInverseLookAndSay()

def main():
    cs112_m20_day5_linter.lint()
    testAll()

if __name__ == '__main__':
    main()
