# SAMS 2017, Programming Section C
#########################################
# Full name:
# Andrew ID:
#########################################

# DUE DATE: THURSDAY JULY 6TH, 9PM.
# SUBMIT THIS FILE TO AUTOLAB. LATE SUBMISSIONS WILL NOT BE ACCEPTED.

# For the functions below, erase the "return 42" line and write the
# appropriate piece of code instead.

# IMPORTANT NOTE:
# You are not allowed to import any modules, or use loops, strings, 
# lists, or recursion.


# Given an integer n, return True if n is even and return False otherwise. 
# Hint: use the % operator.
def isEven(n):
    return 42


# Given an integer n, return the absolute value of that integer. 
def absoluteValue(n):
    return 42


# Given an integer n, return the ones-digit of n,
# i.e. the first digit of n from the right.
def onesDigit(n):
    return 42


# Given an integer n, return the tens-digit of n,
# i.e. the 2nd digit of n from the right.
def tensDigit(n):
    return 42


# Given an integer n and k, return the (k+1)'th digit of n from the right.
# So k = 0 refers to the ones-digit, k = 1 refers to the tens-digit, etc.
# You can assume k is non-negative.
def kthDigit(n, k):
    return 42


# Given integers n, k and d, replace the kthDigit of n with d.
# You can assume k is non-negative, and d is an integer between 0 and 9.
def setKthDigit(n, k, d):
    return 42


# Given a float n, round it to the nearest integer. 
# (Round up in the case of a tie.)
# You are not allowed to use the built-in round function.
def myRound(n):
    return 42 


# Given a float n, round it down to the nearest integer.
# You are not allowed to use anything from the math module.
def floor(n):
    return 42


# Given a float n, round it to the nearest odd integer.
# In case of a tie, round down.
def nearestOdd(n):
    return 42



# If you have written the functions correctly, you should not get any errors
# when you run this file, i.e., you should pass all the tests below.


######################################################################
# ignore_rest: The autograder will ignore all code below here
######################################################################

import math

def testIsEven():
    print("Testing isEven()...", end="")
    assert(isEven(0))
    assert(not isEven(1))
    assert(isEven(2))
    assert(not isEven(3))
    assert(isEven(4))
    assert(not isEven(-1))
    assert(isEven(-2))
    assert(not isEven(-3))
    assert(isEven(-4))
    assert(isEven(123456))
    print("Passed.")

def testAbsoluteValue():
    print("Testing absoluteValue()...", end="")
    assert(absoluteValue(0) == abs(0))
    assert(absoluteValue(1) == abs(1))
    assert(absoluteValue(-1) == abs(-1))
    assert(absoluteValue(2) == abs(2))
    assert(absoluteValue(-2) == abs(-2))
    assert(absoluteValue(3.14) == abs(3.14))
    assert(absoluteValue(-3.14) == abs(-3.14))
    print("Passed.")

def testOnesDigit():
    print("Testing onesDigit()...", end="")
    assert(onesDigit(0) == 0)
    assert(onesDigit(789) == 9)
    assert(onesDigit(7) == 7)
    assert(onesDigit(-1234) == 4)
    assert(onesDigit(-3) == 3)
    print("Passed.")

def testTensDigit():
    print("Testing tensDigit()...", end="")
    assert(tensDigit(0) == 0)
    assert(tensDigit(1) == 0)
    assert(tensDigit(10) == 1)
    assert(tensDigit(21) == 2)
    assert(tensDigit(-1234) == 3)
    assert(tensDigit(-3) == 0)
    assert(tensDigit(-10) == 1)
    print("Passed.")

def testKthDigit():
    print("Testing kthDigit()...", end="")
    assert(kthDigit(0,0) == 0)
    assert(kthDigit(789, 0) == 9)
    assert(kthDigit(789, 1) == 8)
    assert(kthDigit(789, 2) == 7)
    assert(kthDigit(789, 3) == 0)
    assert(kthDigit(-1234, 3) == 1)
    assert(kthDigit(-3, 1) == 0)
    print("Passed.")

def testSetKthDigit():
    print("Testing setKthDigit()...", end="")
    assert(setKthDigit(468, 0, 1) == 461)
    assert(setKthDigit(468, 1, 1) == 418)
    assert(setKthDigit(468, 2, 1) == 168)
    assert(setKthDigit(468, 3, 1) == 1468)
    print("Passed.")

def testMyRound():
    print("Testing myRound()...", end="")
    assert(myRound(0) == 0)
    assert(myRound(1) == 1)
    assert(myRound(-1) == -1)
    assert(myRound(1.1) == 1)
    assert(myRound(1.5) == 2)
    assert(myRound(1.9) == 2)
    assert(myRound(-1.1) == -1)
    assert(myRound(-1.5) == -1)
    assert(myRound(-1.9) == -2)
    assert(myRound(0.1) == 0)
    assert(myRound(0.5) == 1)
    assert(myRound(0.9) == 1)
    assert(myRound(-0.1) == 0)
    assert(myRound(-0.5) == 0)
    assert(myRound(-0.9) == -1)
    print("Passed.")

def testFloor():
    print("Testing floor()...", end="")
    assert(floor(0) == math.floor(0))
    assert(floor(1) == math.floor(1))
    assert(floor(-1) == math.floor(-1))
    assert(floor(1.1) == math.floor(1.1))
    assert(floor(1.5) == math.floor(1.5))
    assert(floor(1.9) == math.floor(1.9))
    assert(floor(-1.1) == math.floor(-1.1))
    assert(floor(-1.5) == math.floor(-1.5))
    assert(floor(-1.9) == math.floor(-1.9))
    assert(floor(0.1) == math.floor(0.1))
    assert(floor(0.5) == math.floor(0.5))
    assert(floor(0.9) == math.floor(0.9))
    assert(floor(-0.1) == math.floor(-0.1))
    assert(floor(-0.5) == math.floor(-0.5))
    assert(floor(-0.9) == math.floor(-0.9))
    print("Passed.")

def testNearestOdd():
    print("Testing nearestOdd()...", end="")
    assert(nearestOdd(0) == -1)
    assert(nearestOdd(13) == 13)
    assert(nearestOdd(12.001) == 13)
    assert(nearestOdd(12) == 11)
    assert(nearestOdd(11.999) == 11)
    assert(nearestOdd(-13) == -13)
    assert(nearestOdd(-12.001) == -13)
    assert(nearestOdd(-12) == -13)
    assert(nearestOdd(-11.999) == -11)
    print("Passed.")

def testAll():
    testIsEven()
    testAbsoluteValue()
    testOnesDigit()
    testTensDigit()
    testKthDigit()
    testSetKthDigit()
    testMyRound()
    testFloor()
    testNearestOdd()
    

testAll()

