Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To begin, add the following function to your program: def multiply_numbers(a, b): This Function Multiplies Two Numbers Together And Stores The Result. result = a

To begin, add the following function to your program:

def multiply_numbers(a, b): """This Function Multiplies Two Numbers Together And Stores The Result.""" result = a * b return result 

Create a test for the multiply_numbers() function to test if two numbers multiplied together equals a given value.The test class should be named TestMultiplyingNumbers

This is the test case.

Add a methodtest_numbers to test the function multiply_numbers()

This is the unit test.

Be sure to call the function multiply_numbers() and set it to a variable named numbers_multiplied

Use the numbers 3 and 4 as the parameters within the function call.

Add the needed unittest method that will do the checking against the number 13

DocStrings are required for the test case and unit test.

Don't forget to import the unittest module.

Run the unit test. Currently, it should fail.

Change the number 13 to 12. Run the program it again. It should now pass.

Part 2

Add the following code to your program. This is another test case:

class TestNewCar(unittest.TestCase): """Tests new_car().""" def test_new_car(self): """Will 2017 Nissan Rogue work?""" new = new_car('Nissan', 'Rogue', 2017) self.assertEqual(new, 'Nice car! 2017 Nissan Rogue') def test_year_output(self): """Will Nice Car! work?""" new_year = new_car('Nissan', 'Rogue', 2009) self.assertEqual(new_year, 'Time for a new car, 2009 Nissan Rogue') 

As you can see, this new test case and its corresponding unit tests test the function new_car. However, that function does not exist.

Write the new_car function.This function should check if the year is greater than or less than 2010. Based on these conditions, it should return the appropriate string (shown above)

Because you are working with strings and numbers, you will need to use the str.format() function to return the correct string in each of the methods.

Do not use the print function; use the returnkeyword

The new_car function should be located above the test case (TestNewCar class).

As you can see in the unit tests, new_car expects three arguments: the car's make, model, and year.

Be sure to run the unit tests to ensure they pass!

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

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions