Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

Exercises 279 In black box (or functional) testing, sample data based on the specification is used. This is termed equivalence partitioning. In white box (or structural) testing, the internal structure of the software is used to select test data. This means that every path through the program is tested. Unit testing tests each component in isolation. Drivers and stubs are used to substitute for missing components. Integration testing tests components as they are brought together. 19.1 Consider a program that has 16 if-then statements in it. Then there are 216 • Exercises possible paths through it. If each test takes 50 microseconds and each action takes 50 microseconds (a gross underestimate), how much computer time is needed to test all program paths? 19.2 Devise black box and white box test data to test the following program. The program specification is: The program inputs a series of integers from the keyboard using a text field. The program finds the largest of the numbers. The numbers are terminated when a button labeled Start Again is pressed. Try not to look at the text of the program, given below, until you have completed the design of the black box data. The program involves the following class: class Biggest { private int largest; } public Biggest() { largest = 0; } public void nextNumber(int n) { if (n > largest) largest = n; } public void display(TextField textField) { textField.setText("largest so far is" + largest); } public void startAgain() { largest = 0; }

280 Chapter 19 ■ Testing 19.3 Devise black box and white box test data to test the following program. The program specification is: The program is to determine insurance premiums for a holiday, based upon the age and gender (male or female) of the client. For a female of age >= 18 and = 31 pays $3.50. A male of age >= 18 and = 36 pays $5.50. People aged 50 or more pay half premium. Any other ages or genders are an error, which is signaled as a premium of zero. The Java code for this program is: public float calcPremium(float age, String gender) { float premium; } if (gender.equals("female")) if ((age >= 18) && (age = 31) premium = 3.50f; else premium = 0.0f; else if (gender.equals("male")) if ((age >= 18) && (age = 36) premium = 5.5f; else premium = 0.0f; else premium = 0.0f; if (age >= 50) premium = premium * 0.5f; return premium; 19.4 Suggest features for software tools that could assist in using each of the following techniques: ■ black box testing ■ white box testing. 19.5 Substantial testing of a system uncovers not a single error. What conclusions would you draw?

Exercises 279<br />

In black box (or functional) testing, sample data based on the specification is used.<br />

This is termed equivalence partitioning.<br />

In white box (or structural) testing, the internal structure of the software is used<br />

to select test data. This means that every path through the program is tested.<br />

Unit testing tests each component in isolation. Drivers and stubs are used to substitute<br />

<strong>for</strong> missing components. Integration testing tests components as they are<br />

brought together.<br />

19.1 Consider a program that has 16 if-then statements in it. Then there are 216 •<br />

Exercises<br />

possible<br />

paths through it. If each test takes 50 microseconds and each action takes 50<br />

microseconds (a gross underestimate), how much computer time is needed to test all<br />

program paths?<br />

19.2 Devise black box and white box test data to test the following program. The program<br />

specification is:<br />

The program inputs a series of integers from the keyboard using a text field. The<br />

program finds the largest of the numbers. The numbers are terminated when a button<br />

labeled Start Again is pressed.<br />

Try not to look at the text of the program, given below, until you have completed the<br />

design of the black box data.<br />

The program involves the following class:<br />

class Biggest {<br />

private int largest;<br />

}<br />

public Biggest() {<br />

largest = 0;<br />

}<br />

public void nextNumber(int n) {<br />

if (n > largest)<br />

largest = n;<br />

}<br />

public void display(TextField textField) {<br />

textField.setText("largest so far is" + largest);<br />

}<br />

public void startAgain() {<br />

largest = 0;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!