Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def test_fib(): This is a suite of tests for the fib function. :return: assert fib(1) == 1 # TODO 1: PLACE YOUR CODE

student submitted image, transcription available below

def test_fib():

"""

This is a suite of tests for the fib function.

:return:

"""

assert fib(1) == 1

# TODO 1: PLACE YOUR CODE HERE

def test_is_prime():

"""

This is a suite of tests for the is_prime function.

:return:

"""

assert is_prime(3) == True

# TODO 2: PLACE YOUR CODE HERE


# Lists to use for binarySearch() and mergeSort() tests

lst1 = [1, 5, 2, 6, 2]

lst2 = [9, 8, 7, 6.5]

lst3 = [5, -3, 7, -3]

lst4 = [1]

lst5 = []

lst6 = ['hello', 'a', 'the']

def test_merge_sort_in_place():

"""

This is a suite of tests for the merge_sort_in_place function.

:return:

"""

# The below lines apply the `merge_sort_in_place` function to the `lst_*`

# lists. After the application the lists should be sorted.

merge_sort_in_place(lst1)

merge_sort_in_place(lst2)

merge_sort_in_place(lst3)

merge_sort_in_place(lst4)

merge_sort_in_place(lst5)

merge_sort_in_place(lst6)

assert lst1 == [1, 2, 2, 5, 6]

# Below, please, write tests based on `lst2` - `lst6`. A sample test for

# `lst1 is provided above.`

# TODO 3: PLACE YOUR CODE HERE

if __name__ == '__main__':

test_fib()

print('-' * 5)

test_is_prime()

print('-' * 5)

test_merge_sort_in_place()
 

In TODO 1, you are going to write programmatic tests for the fib function by completing the body of the test_fib function. The fib function expects an integer greater than or equal to as an argument. It outputs the Fibonacci sequence number that corresponds to the position provided by the argument. The Fibonacci sequence is a sequence of numbers defined by the relation Fn = Fn-1 + Fn-2 (i.e., each element is the sum of the two preceding elements). The first term is and the second is 1. All the subsequent terms can be derived from the provided formula. The first few terms of the Fibonacci sequence are listed below. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,... fib(n): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... n: Your task is to use several assert statements (within the test_fib function) with calls to the fib function using different arguments. The test_fib function can then be used to ascertain that the fib function returns the expected results. Note that you are required to implement at least 5 additional assert statements (there will be 6 in total). Choose the tests so that a correct implementation of the fib function passes but an incorrect implementation fails. Prime Numbers In TODO 2, you are going to write automatic tests for the is_prime function by completing the body of the test_is_prime function. The is_prime function expects an integer greater than e as an argument. It outputs a boolean encoding whether the number is prime or not. A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. For example, 5 is prime because the only ways of writing it as a product, 1 x 5 or 5 x 1, involve 5 itself. Your task is to use several assert statements (within the test_is_prime function) with calls to the is_prime function using different arguments. The test_is_prime function can then be used to ascertain that the is_prime function returns the expected results. Note that you are required to implement at least 5 additional assert statements (there will be 6 in total). Choose the tests so that a correct implementation of the is_prime function passes but an incorrect implementation fails. Sorting Algorithm In TODO 3, you are going to write automatic tests for the merge_sort_in_place function by completing the body of the test_merge_sort_in_place function. The merge_sort_in_place function sorts a list from the smallest to the greatest element. We have not covered lists yet. Please, consider them as a series of elements. Your task is to use several assert statements (within the test_merge_sort_in_place function) with calls to the merge_sort_in_place function using different arguments. The test_merge_sort_in_place function can then be used to ascertain that the merge_sort_in_place function returns the expected results. Note that you are required to implement at least 5 additional assert statements (there will be 6 in total). Choose the tests so that a correct implementation of the is_prime function passes but an incorrect implementation fails. How to Validate Make sure that each of your test_* functions contain at least 6 assert statements testing diverse inputs. Running the task4_test.py file should result in the output shown below. Testing fib(): All tests passed! Testing is_prime(): All tests passed! Testing merge sort():

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Check below code for a complete Python s... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Alcohol and drug use among student athletes

Answered: 1 week ago