Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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

Students also viewed these Databases questions