Software testing

Software testing involves running the program under different conditions to make sure it works.

Even the best programmers make and .

As may only be show up under certain conditions, it is important that mistakes are identified as soon as possible during development so they can be fixed.

Approaches to software testing

Consider the following code to create a simple calculator. Functions are created to add, subtract, multiply and divide two numbers. These functions have then been used to create a square number function and a function to convert Celsius to Fahrenheit.

Pseudocode:

# A simple calculator def add (x, y): return x + y def sub (x, y): return x - y def mul (x, y): return x * y def div (x, y): return x / y def sq(x): return mul(x, x) def tempCon(x): return add(mul(x, div(9, 5)), 32) num = int(input('Enter number to be squared: ')) print(sq(num)) convert = float(input('Enter Celsius temperature: ')) print(tempCon(convert))

Python:

''' A simple calculator program ''' def add (x, y): '''Function to add two numbers''' return x + y def sub (x, y): '''Function to subtract two numbers''' return x - y def mul (x, y): '''Function to multiply two numbers''' return x * y def div (x, y): '''Function to divide two numbers''' return x / y def sq(x): '''Function to square a number''' return mul(x, x) #Calls mul function def tempCon(x): '''Function convert Celsius to Fahrenheit ORDER OF OPERATION - DIVIDE, MULTIPLY, ADD''' return add(mul(x, div(9, 5)), 32) #Calls the div, mul & add functions ###MAIN PROGRAM if __name__ == "__main__": num = int(input('Enter number to be squared: ')) #Collects input from user print(sq(num)) #Passes the input to the sq function and prints the result to screen convert = float(input('Enter Celsius temperature: ')) #Collects input from user print(tempCon(convert)) #Passes the convert variable to the tempCon function & prints to screen