# 15110 Lab 5 - Writing Test Functions - debug_part_two.py

##########################################################
# CLASS ACTIVITY                                         #
##########################################################

# The following function will take 3 lists and interleaves them
# in order of their components.  You may not assume the lists
# will be of the same length.

# An example input will be as follows:
#   listx = [x0,x1,x2,x3]
#   listy = [y0,y1,y2]
#   listz = [z0,z1,z2,z3, z4]
# --> returns [x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,z3,z4]

def class_activity(listx, listy, listz):
    new_list = []
    for i in range(0, len(listx)):
        new_list.append(listx[i])
        new_list.append(listy[i])
        new_list.append(listz[i])
    return new_list

# Fill in the test cases using an assert statement
# to find the problem with the code!
# Provide a brief explanation of what the bug is and which test case fails:
# -->
def test_class_activity():
    #Test Case 1:
    print("Running Test Case 1...")
    assert(False)
    print ("Test Case 1 Passed!")
    #Test Case 2:
    print("Running Test Case 2...")
    assert(False)
    print ("Test Case 2 Passed!")
    #Test Case 3:
    print("Running Test Case 3...")
    assert(False)
    print ("Test Case 3 Passed!")
    print("Test Class Activity Success")

##########################################################
# CLASS ACTIVITY                                         #
##########################################################

# Problem 1
#---------------------------------------------------------
# The function will take a list of integers greater than
# 2 and will return all the numbers in the list that are 
# prime.  You can assume that no number will have more
# than one entry in the list.

def f1(integer_list):
    primes_list = []
    for possible_prime in integer_list:
        is_prime = True
        for i in range(2,possible_prime):
            if (possible_prime % i == 0):
                is_prime = False
            if (is_prime):
                primes_list.append(possible_prime)
    return primes_list
    

# Fill in the test cases using an assert statement
# to find the problem with the code!
# Provide a brief explanation of what the bug is and which test case fails:
#-->
def test_f1():
    #Test Case 1:
    print("Running Test Case 1...")
    assert(False)
    print ("Test Case 1 Passed!")
    #Test Case 2:
    print("Running Test Case 2...")
    assert(False)
    print ("Test Case 2 Passed!")
    #Test Case 3:
    print("Running Test Case 3...")
    assert(False)
    print ("Test Case 3 Passed!")
    print("Test F1 Success")

# Problem 2
#---------------------------------------------------------
# The following function will find the maximum element in
# the list and it will return the element in the list that
# is immediately before it.  If the list is empty or
# there is no element before# the max element in the list 
# then return None. 

def f2(integer_list):
    maximum_found = -1
    maximum_found_index = -1
    for i in range(0,len(integer_list)):
        if (integer_list[i] > maximum_found):
            maximum_found = integer_list[i]
            maximum_found_index = i
    return integer_list[maximum_found_index-1]

# Fill in the test cases using an assert statement
# to find the problem with the code!
# Provide a brief explanation of what the bug is and which test case fails:
#-->
def test_f2():
    #Test Case 1:
    print("Running Test Case 1...")
    assert(False)
    print ("Test Case 1 Passed!")
    #Test Case 2:
    print("Running Test Case 2...")
    assert(False)
    print ("Test Case 2 Passed!")
    #Test Case 3:
    print("Running Test Case 3...")
    assert(False)
    print ("Test Case 3 Passed!")
    print("Test F2 Success")

# Problem 3 - This is hard.  Give it a try if you have time
#---------------------------------------------------------
# The following function will recursively find a value
# in an ordered list (from low to high) using binary
# search.  It will return True if the element is in the
# list else it will return False  


# Hint: if you are unsure of how the recursion works, 
#      try printing ordered list at the top of the function!

def f3(ordered_list, key):

    # print(ordered_list)

    # base case
    if (len(ordered_list) == 1 and ordered_list[0] == key):
        return True
    if (len(ordered_list) == 1 and ordered_list[0] != key):
        return False

    pivot_index = len(ordered_list)//2

    #recursive case
    if (key < ordered_list[pivot_index]):
        return f3(ordered_list[0:pivot_index-1], key)
    else:
        return f3(ordered_list[pivot_index:len(ordered_list)], key)


# Fill in the test cases using an assert statement
# to find the problem with the code!
# Provide a brief explanation of what the bug is and which test case fails:
#-->
def test_f3():
    #Test Case 1:
    print("Running Test Case 1...")
    assert(False)
    print ("Test Case 1 Passed!")
    #Test Case 2:
    print("Running Test Case 2...")
    assert(False)
    print ("Test Case 2 Passed!")
    #Test Case 3:
    print("Running Test Case 3...")
    assert(False)
    print ("Test Case 3 Passed!")
    print("Test F3 Success")
