0% found this document useful (0 votes)
2 views15 pages

Testing

The document discusses various programming concepts related to error types, testing techniques, and code examples in Python. It highlights specific functions and their potential errors, as well as testing methodologies such as path coverage and statement coverage. Additionally, it includes exercises to identify errors in code and suggests testing strategies for different functions.

Uploaded by

ayathokoza08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Testing

The document discusses various programming concepts related to error types, testing techniques, and code examples in Python. It highlights specific functions and their potential errors, as well as testing methodologies such as path coverage and statement coverage. Additionally, it includes exercises to identify errors in code and suggests testing strategies for different functions.

Uploaded by

ayathokoza08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Testing

Consider this Python function:


def Maximum(x,y):
z=x
if (x<y) z=y
return z
The function contains an error. This error is:
a) A syntax error.
b) A run-time error.
c) A logic error.
d) All of the above.
The following is an example of a
Glass Box testing method:
a) Equivalence Classes
b) Path Coverage Testing
c) Random Testing
d) Exhaustive Testing
e) None of the above
Given the Python function:
def Minimum(x,y):
z=x
if (x>y): z=y
return z
The function call Minimum(3,2)constitutes
a) A complete path coverage test.
b) A complete statement coverage test.
c) All of the above.
d) None of the above
Consider the following Python program.
def Cat(x):
if (x<0): return 0
if (0<x<100):return x
if (x>100): return 100
Select the set of inputs below that will comprise a
complete, but minimal, path coverage test of this
function.
a.-200
b.-20, 65, 100
c.-40, 0, 78, 200
d.-50, 0, 65, 100, 200
e.-80, 0, 45, 67, 100, 200
Consider the following Python
program.
def SumList(lst):
for a in lst:
total=total+a
return total
a.The function has a syntax error.
b.The function has a runtime error.
c.The function has a logic error.
d.All of the above.
e.None of the above.
Dividing a number by 0 in Python is equal to:

a. 0
b. 1
c. the number itself
d. compile time error
e. runtime error
Testing code with all the possible input values is
called:

a. Equivalence class testing


b. Boundary value testing
c. Exhaustive testing
d. Path testing
e. Statement coverage testing
Consider the code below. Selecting the input 5 to test this
code would be an example of which testing technique/s?
num = eval(input("Enter a number: "))
if (num < 10):
print('Num is smaller than 10')
print('This statement will always be executed')
a. Complete path testing
b. Complete statement testing
c. Boundary value testing
d. Complete equivalence class testing
e. Complete path and statement testing
Long Questions
#Module Q5.py You are asked to test the
def Myst(n): Myst(n)function using a range of
output=[] testing strategies.
a) Does the function call Myst(6)
a,b=1,1
constitute statement coverage testing
for i in range(n): of function Myst? Explain your
output.append(a) answer.
a,b=b,a+b b) Write down a minimal set of inputs to
return output this function that would constitute a
print(Myst(6)) complete path test.

Write down the exact output when the


Q5.py module is executed.
def mystery(arr, s):
temp = []
for item in arr: Write down a minimal set
if s == item[1]:
temp.append(item) of inputs to the
return temp mystery() function
name_list = that would constitute a
[["Jon","Snow"],["Daenerys","Tar
garyen"], complete path test of the
["Arya","Stark"],["Tyrion","Lann function.
ister"],
["Sansa","Stark"],["Bran","Stark
"], ["Cersei","Lannister"]]

new_list = mystery(name_list,
"Stark")
print(new_list)
def search(word):
the_list = [ 'i', 'love', 'computer', 'science' ]
position = 1
while the_list[position]!=word and position<len(the_list):
position = position + 1
print (position)

What is an equivalence class?

Provide a minimal set of test values to support statement coverage


testing of this function.

If we use an exhaustive testing method, we will find that there are 2


errors in this program. Explain what they are; whether each is a syntax
error or logic error; and how to fix each error.
Examine the following code. Identify the error(s) and
rewrite the code by fixing the error(s).
a=10
if a<=10
print("a is a small value)
else:
print("a is a big value")

Define the statement coverage testing technique. Is it a


black box testing technique?
For the following erroneous code snippets, specify the
type of error, and provide correct versions of the code.
Assume that a is a non-empty list.
def median(a):
if len(a) % 2 == 0:
mid = len(a)/2
return (a[mid-1] + a[mid])/2
else:
return a[(len(a)-1)/2]

You might also like