[Solved] CMPT141 Assignment8-Testing and Debugging

$25

File Name: CMPT141_Assignment8-Testing_and_Debugging.zip
File Size: 386.22 KB

SKU: [Solved] CMPT141 Assignment8-Testing and Debugging Category: Tag:
5/5 - (1 vote)

Question 1

Purpose: To practice testing functions you wrote yourself.

Degree of Difficulty: Moderate

In digital advertising, data is extremely important to measure success of a campaign. In this assignment, we are going to calculate two commonly used digital advertising measurements, write test cases, and create a test driver for those test cases. The equations for the measurements are below:

eCPM (effective cost per mille)

eCPM = ( Total Ad Spend / Total Ad Impressions )1000

ARPDAU (average revenue per daily active user)

ARPDAU = ( Revenue / Active Users / Days )

Write the following functions:

  • calculate_ecpm(ad_spend, ad_impresions) takes 2 integer parameters and returns a float representing calculated eCPM. Your function should return 0.0 for incorrect input.

For Example:

> calculate_ecpm(152, 1013) > 150.05

  • calculate_arpdau(user_list, revenue_list) takes 2 list parameters and returns a float representing calculated ARPDAU. Both lists should be the same length and include numbers only. You will need to sum the values in each list. Your function should return 0.0 for incorrect input. For Example:

> calculate_arpdau([54,36,30,96,112,130],[40.05,15.11,16.07,26.90,79.68,114.12]) > 0.1062

Inside both functions, use the round() method to limit the number of decimal places shown in the results. calculate_ecpm should round to 2 decimal places while calculate_arpdau should round to 4 decimal

places. An example of using round():

> round(1.259483,2)

> 1.25

To show that your functions are working correctly, implement a test driver which thoroughly tests both functions with a variety of white-box tests (at least six per function). You can use either plain if-statements (as demonstrated in readings 15.2.4) or a list-of-dictionaries to implement your test driver (as demonstrated in class during chapter 15 exercise 3).

Question 2

Purpose: To practice testing and debugging code that someone else wrote.

Degree of Difficulty: Moderate

In the provided file a8q2_functions.py youll find two functions:

  • isValidPhoneNumber(): Returns True if the provided phone number (represented as a string) is correctly formatted, otherwise False. To be considered correctly formatted, phone numbers must be written as ###-###-####, where # is a digit between 0 and 9.
  • validatePhoneBook(): A phone book is a list where each entry is a phone book record (represented as a dictionary; see below for more details). This function checks each phone book record in the phone book for correctly formatted phone numbers.

A phone book record is a dictionary which initially has two keys: the key name mapped to the contacts name (string) and the key phone number mapped to that contacts phone number (also a string). validatePhoneBook() adds a new key valid to the record with the value True if the phone number is formatted correctly, otherwise False.

# before[ { name : Department of Computer Science,phone number : 306-966-4886 },{ name : Department of History,phone number : 306.966.8712 } ]# after[ { name : Department of Computer Science,phone number : 306-966-4886,valid : True },{ name : Department of History,phone number : 306.966.8712,valid : False } ]

Here is how a sample phone book might look before and after validatePhoneBook():

The provided functions contain errors. Your task will be to find the errors by systematically testing. Youll hand in an explanation of what the errors are, and how you fixed them, but you will not hand in the corrected code.

Part of the exercise is figuring out what the code is supposed to do based on the documentation!

  1. Write white-box and black-box tests for the function isValidPhoneNumber(). You should do this without Python, either on paper, or in a simple document. Dont worry about running your tests until you have thought about which test cases you want. Make sure you have at least 3 black-box tests and 3 white-box tests. More tests may be useful.
  2. Implement a test driver using your test cases in a document named a8q2_testing.py. This should be done using the techniques seen in the textbook (Chapter 15) and as demonstrated in class (Chapter 15 Exercise 3).
  3. Run your tests and copy/paste the console output to a document named a8q2_output.txt. The console output you hand in should come from the program before you try to fix it!
  4. Try to deduce the problems with the isValidPhoneNumber() function from the output of your testing. Then fix the error(s) in the function!
  5. In the document a8q2_output.txt, describe the error(s) you found and how you fixed it (them). You do not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the functions.
  6. Repeat the above steps for the second function validatePhoneBook().

Note: When writing your test driver for validatePhoneBook(), you can assume existing keys and values in a phone book will be unchanged. In other words, it is sufficient to only check whether the key valid exists and is paired with the correct value in each phone book record after validatePhoneBook() is called.

Be sure to include your name, NSID, student number, course number, lecture section and laboratory section at the top of all documents submitted.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CMPT141 Assignment8-Testing and Debugging
$25