Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 (8 points): Purpose: To create white-box tests for a function you wrote yourself. Degree of Difficulty: Moderate, only because some students struggle with

image text in transcribed
Question 2 (8 points): Purpose: To create white-box tests for a function you wrote yourself. Degree of Difficulty: Moderate, only because some students struggle with white-box test reasoning White-box tests need to be created after the function being tested has been written. The idea behind white-box testing is that perhaps looking at/writing the code will give you an idea for a test case that you may not have thought of othenwise. For this question, youll create some white-box tests to test a function that you wrote yourself. The closest_to_zero() function Write a function called closest_to_zoro(nus1, num 2 , num 3). The function should have 3 parameters which are each integers, and returns the value that is closest to 0 from among those 3 . For example, given the inputs 2,7 and 0 , the function should return 0 . Given the inputs 3,1 and 5 , the function should return 1. It is possible that there is a tie. For example, 1 and 1 are equally close to 0 . In the case of a tie between a positive and negative value, the function should return the positive value. Hint the abs () function may be useful in your solution. Write a test driver Write a test driver that contains several tests for the closest_ to zero ( function. Use the examples of the textbook to get an idea for the format of the tests. Choose your test cases thoughtfully. using insights gained from writing the code. Think about every single individual line of code that you wrote, and how you might create a test case to test that line. Do NOT bother with test cases that use incorrect data types (i.e. passing in strings instead of integers). Exactly how many test cases to use is up to you, include as many as you think you need to be confident that your function is correct. What to Hand In - A document called a 3q2v1.py containing your function. - A document called a3q2v1 testdriver.py containing your test driver. This file can import your function from a 3 q2v1. py in order to test it. The version number (v) portion of the file names must be changed to v2, v3 etc. each time you resubmit your assignment. Remember to include all your solution files each time you submit/resubmit your assignment. Evaluation - 2 marks: Your function closest_to_zero () takes three integers and correctly finds the integer closest to zero. - 3 marks: The form of the test driver (calling the function, comparing the result to a correct expected result is correct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions