Determine the expected output of your tests yourself

Assignment Help Python Programming
Reference no: EM132367439

Programming Principles Assignment - Testing and Quality Assurance

Task 1 - Testing Boundaries and Edge Cases

Here is the code to define a small function named "countNum()":

def countNum(start, end, num):

count = 0

for i in range(start, end):

if str(num) in str(i):

count = count + 1

return count

The "countNum()" function tries to implement the following behaviour:

It requires 3 parameters, all of which should be integers: start, end, num.

The function aims to count (and return) how many times num appears in the numbers between (and including) start and end.

  • e.g. With a start of 1, an end of 25 and a num of 4, the function should return 3, since the number 4 appears in 4, 14 and 24.
  • A simple test confirms that "print(countNum(1, 25, 4))" results in 3.

Come up with some inputs that you feel will test how well the function works and try to identify any bugs it may contain. For now, only test boundaries and edge cases, not invalid or unexpected input.

Be sure to include test cases that check the following:

  • Inputs resulting in 0, e.g. start = 1, end = 5, num = 8 should return 0
  • Inputs resulting in a large result, e.g. start = 1, end = 500, num = 2 should return 176
  • Inputs involving a negative start or end, e.g. start = -50, end = -5, num = 6 should return 5
  • Inputs where num is larger than 9, e.g. start = 100, end = 1000, num = 42 should return 19
  • Inputs where num is in start or end, e.g. start = 1, end = 12 , num = 1 should return 4
  • Inputs where all parameters are the same, e.g. start = 5, end = 5 , num = 5 should return 1

Test a few of your test cases manually, then write some basic code to automate it - see slides 17 and 18 of Lecture 10 for an idea of how to do this.

Remember to determine the expected output of your tests yourself - you can't rely upon what the function returns at this stage since it is untested and would defeat the purpose of the testing!

Task 2 - Debugging

Hopefully your testing revealed a bug in the "countNum()" function. It relates to how the "range()" function works, and it can be fixed by adding just two characters to the code. Fix the bug, and perform the tests again to confirm that the function is now working correctly.

Task 3 -Testing Invalid and Unexpected Input

Now let's decide how the function should behave when given invalid or unexpected input and test for that. I have provided a list of test cases and expected outputs for invalid or unexpected input:

I've specified that if input of an inappropriate type (whether it be float, string, or any other type) is provided for any of the parameters, a TypeError exception should be raised. If the parameters are all integers but the start parameter is greater than the end parameter or the num is negative, a ValueError should be raised - since the data types are correct, but the values are not.

Your task is to enhance your basic automated testing code from Task 1 so that it performs these seven invalid and unexpected input tests as well as the previous tests for boundaries and edges. See slide 22 of Lecture 10 for an example of this.

Run the tests and try to determine which ones pass and which ones fail.

Task 4 - More Debugging

Hopefully your testing revealed the "countNum()" function behaves as desired for some of the tests, but resulted in 0 instead of raising an exception for some of the other tests.

Examine the test results and the function code until you are able to determine why the test results are as they are, and then try to modify the function so that it behaves as desired for all test cases.

One way to implement this is to add a series of "if" statements to the start of the function that test a condition and raise an exception if needed, e.g:

if type(start) != int:

raise TypeError('start parameter must be an integer')

Similar code can be used to check the type of the other parameters, and to check whether start is greater than end and whether num is less than 0, and raise the appropriate exception (with an appropriate error message) for each case.

Task 5 - Testing with the "unittest" Module

Similar to how the example in Lecture 10 progressed, try to now use the "unittest" module to test the function. Use the code from slide 26 of Lecture 10 as an example.

Follow these steps to do this:

1. Copy the code of the "countNum()" function into a new file and save it as "countnum.py".

2. Create a new Python program and use the code from slide 26 of Lecture 10 as an example:

  • Import "unittest" and your "countnum" file.
  • Create a class that expands the "unittest.TestCase" class.
  • Create methods inside it with names starting in "test", that use assertions to test the test cases. You should only need "assertEqual() and "assertRaises()".

Note that "assertRaises()" requires the inputs to be specified as separate parameters, e.g. "self.assertRaises(TypeError, countnum.countNum, 1.5, 9, 5)".

Test your code and make sure that it is working.

Attachment:- Programming Principles Assignment File.rar

Reference no: EM132367439

Questions Cloud

Create a program that shows an image with Toggle Image : Using this knowledge and what we have covered in the lecture, create a program that shows an image and a Button with "Toggle Image" written on it
Estimate just the value that maximizes the mle function : If the parameter is not known but it has been narrowed down to 3 possible values, is the maximum likelihood estimate just the value
How many different ways can a senior project manager : How many different ways can a senior project manager and an associate project manager be selected for an analytics project if there are seven data scientists av
What percent of the entrants had distances : What percent of the entrants had distances between 150 and 160 feet? Round your answer to two decimal places.
Determine the expected output of your tests yourself : CSP1150/CSP5110 Programming Principles Assignment - Testing and Quality Assurance, Edith Cowan University, Australia. Determine expected output of your tests
Drawn without replacement from an ordinary deck : Two cards are drawn without replacement from an ordinary deck. Find the probability that two jacks are drawn. Give your answer as a simplified fraction.
What is the 55th percentile of this distribution : What is the 55th percentile of this distribution? (Recall: The 55th percentile divides the distribution in to 2 parts so that 55% of area is to the left of 55th
Confidence interval for the true proportion of all employees : A 95% confidence interval for the true proportion of all employees at this workplace who were satisfied with their position is between
Prepare a statement of cash flows for the year : BUACC 5930 - Accounting Concepts and Practices - Federation University - Prepare a statement of cash flows for the year ended 30 June 2021 in accordance

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd