Chapter 2.6: Testing and running a solution

Similar documents
Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered.

How to approach a computational problem

Intro. Scheme Basics. scm> 5 5. scm>

After completing this appendix, you will be able to:

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Testing. UW CSE 160 Winter 2016

Using loops and debugging code

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Introduction to Programming

Post Experiment Interview Questions

Chapter 5 Errors. Bjarne Stroustrup

BTEC Nationals IT - Unit2 FAQs

The compiler is spewing error messages.

Divisibility Rules and Their Explanations

EC121 Mathematical Techniques A Revision Notes

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Table of Laplace Transforms

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

Alverton Community Primary School

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

EXAMINING THE CODE. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist:

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

(Refer Slide Time: 02.06)

Create your first workbook

St. Benedict s High School. Computing Science. Software Design & Development. (Part 1 Computer Programming) National 5

Part II Composition of Functions

VB Net Debugging (Console)

Expressions and Casting

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

T H E I N T E R A C T I V E S H E L L

Chapter 9. Software Testing

Algebra 2 Common Core Summer Skills Packet

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software.

Scheme of work Cambridge International AS & A Level Computing (9691)

Computer Science Lab Exercise 1

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Programming and Data Structure

In math, the rate of change is called the slope and is often described by the ratio rise

(I m not printing out these notes! Take your own.)

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

COMP12111 Fundamentals of Computer Engineering Paul Nutter Vasilis Pavlidis Comments

An Interesting Way to Combine Numbers

Three Types of Probability

Dealing with Output. Producing Numeric Output CHAPTER 3. Task. Figure 3-1. The program in action

EDIT202 Spreadsheet Lab Prep Sheet

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

C A R I B B E A N E X A M I N A T I O N S C O U N C I L REPORT ON CANDIDATES WORK IN THE SECONDARY EDUCATION CERTIFICATE EXAMINATIONS MAY/JUNE 2010

Teaching guide: Structured programming

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

5. Control Statements

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

Course: Programming 101 Introduction to Python. CIP Course Title / Code: Computer Programming / Duration: Part one of a two-semester series

Chapter 9: Dealing with Errors

Students received individual feedback throughout year on assignments.

(Refer Slide Time: 00:51)

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3 5 CHAPTER 4. Algorithm Design & Problem Solving. Data Representation.

GAP CLOSING. Grade 9. Facilitator s Guide


If Statements, For Loops, Functions

AXIOMS OF AN IMPERATIVE LANGUAGE PARTIAL CORRECTNESS WEAK AND STRONG CONDITIONS. THE AXIOM FOR nop

Exercises: Instructions and Advice

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

Devel::Cover - An Introduction

Evaluating Expressions Using the Order of Operations

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Subtracting with Multi-Digit Numbers Adaptable for 2 nd, 3 rd, 4 th, and 5 th grades*

NON-CALCULATOR ARITHMETIC

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Let s Make a Front Panel using FrontCAD

Lecture 10: Introduction to Correctness

Here we will look at some methods for checking data simply using JOSM. Some of the questions we are asking about our data are:

CS 142 Style Guide Grading and Details

CSC 258 lab notes, Fall 2003

Step through Your DATA Step: Introducing the DATA Step Debugger in SAS Enterprise Guide

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Imelda C. Go, South Carolina Department of Education, Columbia, SC

Usability Test Report: Bento results interface 1

CS112 Lecture: Repetition Statements

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

Graphics calculator instructions

Testing and Debugging

Project 1 Balanced binary

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras

2.Simplification & Approximation

Debugging Your Python Code: For Dummies

PIETRO, GIORGIO & MAX ROUNDING ESTIMATING, FACTOR TREES & STANDARD FORM

CS 161 Computer Security

GAP CLOSING. Integers. Intermediate / Senior Facilitator s Guide

LAB 5 Implementing an ALU

APPENDIX B. Fortran Hints

SECTION 3. ROUNDING, ESTIMATING, AND USING A CALCULATOR

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Control Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur

Iteration. # a and b are now equal # a and b are no longer equal Multiple assignment

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

Transcription:

Chapter 2.6: Testing and running a solution 2.6 (a) Types of Programming Errors When programs are being written it is not surprising that mistakes are made, after all they are very complicated. There are three types of error which can be made when program code is being produced. 1. Syntax errors. These are errors in the use of the language. The rules have been broken. A command word might be PRINT. If it was typed in as PLINT the translator program would not recognise it and so would not be able to translate it. This is not a difficult error to spot because when the programmer tells the translator to translate it, a message will be returned saying that a mistake has been made and telling the programmer which word it cannot recognise. There are other ways of breaking the rules, for instance a language might be set up to only accept a mathematical formula if it is in the form of a variable followed by an equals sign and then a collection of variables. So X = 3*(2+A) would be accepted by the translator, but 3*(2+A) = X would be rejected as an error even though, mathematically, it is identical. The following code contains many different syntax errors: DIM X no data-type has been stated X=1 IF X > 1 no THEN statement Y=(2*X+3 no closing bracket PLINT Y misspelling of a keyword NEXT NEXT statement without a FOR (Should have been END IF) 2. Logic errors (Run Time). A logic error is a mistake in the way the program solution has been designed. For example, an instruction in a program may tell the computer to jump to another part of the program. This is fine as long as the instruction tells the computer to go to the right part of the program. If it tells the computer to go to the wrong place, it is highly unlikely that the program will produce the results that were expected. Unfortunately, such a mistake does not usually make the program stop working; it just makes it produce wrong results. This makes it difficult to spot that a mistake has been made, and even when the programmer realises that something has gone wrong, finding where the error is can be very difficult. Another example of a typical logic error is when an incorrect formula is used e.g. Total_number = Previous_total New_number. There is nothing obviously wrong with the formula so it will work, but it won t produce the right answer because it should have been +. Notice that this is not an arithmetic error, the computer will do the arithmetic perfectly, and it is the logic that is wrong. Page 1 of 8

3. Arithmetic error. This is sometimes thought of as a type of logic error but is rather different because the computer is asked to do something that is impossible. A good example is when a computer is asked to divide by 0, this is impossible and would cause the program to fail. The following code will produce an arithmetic error on the fourth line because X was initialised to zero and the first iteration will attempt to divide by X when it is this initial value: X=0 X is initialised to zero Y=1 FOR i=1 TO 10 Y=Y/X attempted division by zero on first iteration X=X+i NEXT Page 2 of 8

2.6 (b) Testing Methods When a system is designed it is important that some consideration is given to making sure that no mistakes have been made. A schedule should be drawn up which contains a test for every type of input that could be made and methods of testing that the program actually does what it was meant to do. This schedule is known as the test plan. Note that it is produced before the system is produced. There are a number of ways of testing a program. 1. Black box: Different values can be input for variables to determine whether the program can cope with them. These values should include typical values, borderline values and values which are not acceptable. For example, if a program is written which uses marks out of 100 from a maths examination as input, the test data would include typical data like 27, 73.., borderline data which would be 0 and 100, and unacceptable data like 34, 123, 16.345 This type of testing is called black box testing. 2. White box testing is testing the program to determine whether all the possible paths through the program produce the desired results. As a large program can have a very large number of routes, when you take into account the different condition statements and loops, white box testing is rarely carried out exhaustively. Think of black box as a test where you cannot see into the box (program) all you see is what comes out at the end. White box testing means that you are able to see what is happening as the data goes through the box because it is transparent. 3. Alpha and Beta testing. When you have written a program and you sit down to test it, you have a certain advantage because you know what to expect. After all, you wrote the program. This can be extended to the whole software company, as the employees are all computer-minded people. Testing carried out by people like this is known as alpha testing. Eventually, the company will want ordinary users to test the program because they are likely to find errors that the software specialists did not find. Testing carried out by the users of the program is called beta testing. If you continue the course next year, in order to turn your AS grade into an A level, you will have to write a project. This involves using a computer to solve a problem for someone. When you have finished your project you will be expected to test whether or not it works, this is alpha testing. You will also get marks if you persuade the person whose problem you are solving to test it for you, this is the beta testing. 4. User Acceptance Testing is often the final step before rolling out the application. Usually the end users who will be using the applications test the application before accepting the application. This type of testing gives the end users the confidence that the application being delivered to them meets their requirements. This testing also helps nail bugs related to usability of the application. Page 3 of 8

2.6 (c) Selection of test data If a solution is to be tested, someone has to choose what data is going to be used to do the testing. The test data is usually chosen by the programmer because they know what they want to test. It is important to test as many different things as possible, the important word there being different. The problem for the programmer is that they know what inputs were expected so they find it very difficult to think of the sort of inputs that the user of the program might try to put in. When you are asked to think up different inputs to test a program, it must be different types of input, not just changing numbers. Imagine a question that states that a program has been written that will work out the mean of three numbers. You have to come up with different test data and the reasons for doing those tests. That last bit is in bold because that is what you get the marks for and the reasons for the tests are the things that have to be different. In this example you would me thinking of 1, 2, 3 to test whether integers will give an integer answer 1, 2, 4 to test whether the software can cope with a recurring decimal answer (Note that 1, 2, 4 to test a different set of integers would not get a mark because the reason for the test is not different) 1, 2.5, 3 to test whether the program can use decimal inputs 1, 2½, 3 to test whether fractions are allowed -1, -2, -3 to test whether negative numbers can be handled 1, 2 to test what happens when only two values are input There are many more that would be acceptable. The important thing to notice is that the numbers themselves are almost identical but that the reasons for choosing them are very different. Also pay attention to NORMAL, ABNORMAL and BORDERLINE data. Example: Software calculates the cost of parking at a council car park as follows: Free from 5am to 8am 3 per hour or part of an hour between 8am and 5pm Free from 5pm to 12 midnight No parking from 12 midnight to 5am Solution: Suitable test data will include: data within each of the valid parking periods; data that crosses more than one of the valid parking periods data at the boundaries of the valid parking periods; data not within the valid parking periods. The test data should be presented in a table similar to the following: Page 4 of 8

Example: A procedure has been written which will accept any two numbers and output the larger. Give different sets of data, which could be used to test the procedure. Solution: Page 5 of 8

2.6 (d) Trace tables and dry run Students should do class practices with related past paper questions to learn dry running/desk checking an algorithm with the help of their teachers. Page 6 of 8

2.6 (e) Debugging Errors in computer solutions are called bugs. They create two problems. One is that the error needs to be corrected; this is normally fairly straightforward because most errors are caused by silly mistakes. The second problem, however, is much more complicated, the errors have to be found before they can be corrected. Finding where the error is and identifying it, can be very difficult and there are a number of techniques available for solving such problems. 1. Translator diagnostics. Each of the commands that are in the original program is looked at separately by the computer translator to execute it. Each command will have a special word which says what sort of command it is. The translator looks at the special word in the command and then goes to its dictionary to look it up. The dictionary tells the translator program what the rules are for that particular special word. If the word has been typed in wrongly, the translator will not be able to find it in the dictionary and will know that something is wrong. If the word is there, but the rules governing how it should be used have not been followed properly, the translator will know that there is something wrong. Either way, the translator program knows that a mistake has been made, it knows where the mistake is and, often, it also knows what mistake has been made. A message detailing all this can be sent to the programmer to give hints as to what to do. These messages are called translator diagnostics. 2. Debugging tools. Sometimes the program looks alright to the translator, but it still doesn t work properly. Debugging tools are part of the software which help the user to identify where the errors are. The techniques available include: a) Cross-referencing. This software checks the program that has been written and finds places where particular variables have been used. This lets the programmer check to make sure that the same variable has not been used twice for different things. b) Traces. A trace is where the program is run and the values of all the relevant variables are printed out, as are the individual instructions, as each instruction is executed. In this way, the values can be checked to see where they suddenly change or take on an unexpected value. c) Variable dumps (check/watch). At specified parts of the program, the values of all the variables are displayed to enable the user to compare them with the expected results. 3. Desk checking is sometimes known as a dry run. The user works through the program instructions manually, keeping track of the values of the variables. Most computer programs require a very large number of instructions to be carried out, so it is usual to only dry run small segments of code that the programmer suspects of harbouring an error. 4. In section 2.1.c we discussed the splitting up of a problem into smaller and smaller parts, until each part was a manageable size. When the parts were combined they would produce a solution to the original problem. Because we are starting with a big problem and splitting it into smaller problems, this was called top-down design. When the program is written, each small program is written separately, allowing the small programs to be tested thoroughly before being combined. This is called bottom-up programming. The technique is particularly useful for testing the Page 7 of 8

finished program because it is far easier to test a lot of small programs than it is to test one large one. One problem can arise, because the small programs have to be joined together, these joints have to be tested too to make sure that no silly mistakes have been made like using the same variable name for two different things in two parts of the program (tested by cross referencing). 5. Test strategies are important to establish before the start of testing to ensure that all the elements of a solution are tested, and that unnecessary duplication of tests is avoided. 6. (This section is with respect to VB6) If you reach a point in your code that calls another procedure (a function, subroutine, or the script associated with an object or applet), you can enter (step into) the procedure or run (step over) it and stop at the next line. At any point, you can jump to the end (step out) of the current procedure and carry on with the rest of the application. You may want to step through your code and trace code execution because it may not always be obvious which statement is executed first. Use these techniques to trace the execution of code: Break points can be set within program code so that the program stops temporarily to check that it is operating correctly to that point. Step Into: Traces through each line of code and steps into procedures. This allows you to view the effect of each statement on variables. Step Over: Executes each procedure as if it were a single statement. Use this instead of Step Into to step across procedure calls rather than into the called procedure. Step Out: Executes all remaining code in a procedure as if it were a single statement, and exits to the next statement in the procedure that caused the procedure to be called initially. Run To Cursor: Allows you to select a statement in your code where you want execution to stop. This allows you to "step over" sections of code (for example, large loops). To trace execution from the current statement From the Debug menu, choose Step Into, Step Over, Step Out, or Run To Cursor. To trace execution from the beginning of the program From the Debug menu, choose Step Into, Step Over, Step Out, or Run To Cursor. Page 8 of 8