Question: I need to add a test case which does the following add a test with additional arguments, such as circ_area(radius=3,foo=20,bar=10) However, we do not want

I need to add a test case which does the following

add a test with additional arguments, such as circ_area(radius=3,foo=20,bar=10)

However, we do not want you to call the function like this. Instead, we want you to create a dictionary that has the additional arguments and pass this dictionary to circ_area using keyword expansion.

Below is the code for the function I need to do a test case (func)

import math def circ_area(**kwd):

if not kwd: raise AssertionError L = kwd.keys()

if 'radius' in L and 'diameter' in L: raise AssertionError

for key in kwd:

if key == 'radius': return round((math.pi * kwd['radius'] * kwd['radius']),5)

if key == 'diameter': return round(((1/4)*math.pi * kwd['diameter'] * kwd['diameter']),5)

raise AssertionError

Below is the testing code

import introcs import func

def test_circ_area(): """ Test procedure for function circ_area(). """ print('Testing circ_area()') result = func.circ_area(radius=3) introcs.assert_floats_equal(28.27433,result) result = func.circ_area(radius=2) introcs.assert_floats_equal(12.56637,result) result = func.circ_area(diameter=4) introcs.assert_floats_equal(12.56637,result) # Test for crashes try: func.circ_area() introcs.assert_true(False) # We should never reach this line! except: pass try: func.circ_area(radius=3,diameter=6) introcs.assert_true(False) # We should never reach this line! except: pass # Add a test with additional arguments

if __name__ == '__main__': test_circ_area() print('Module func passed all tests.')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!