CMSE326 Problem Session 23.05.2016
Chapter 7 Decision Table-Based Testing Exercises
Program triangle3’
Dim a, b, c As Integer
Dim c1, c2, c3, IsATriangle As Boolean
‘Step 1: Get Input
Do
Output(“Enter 3 integers which are sides of a triangle”)
Input(a, b, c)
c1 = (1 ≤ a) AND (a ≤ 300)
c2 = (1 ≤ b) AND (b ≤ 300)
c3 = (1 ≤ c) AND (c ≤ 300)
If NOT(c1) Then
Output(“Value of a is not in the range of permitted values”)
EndIf
If NOT(c2) Then
Output(“Value of b is not in the range of permitted values”)
EndIf
If NOT(c3) Then
Output(“Value of c is not in the range of permitted values”)
EndIf
Until c1 AND c2 AND c3
Output(“Side A is”,a)
Output(“Side B is”,b)
Output(“Side C is”,c)
‘Step 2: Is A Triangle?
If (a < b + c) AND (b < a + c) AND (c < a + b) Then
IsATriangle = True
Else
IsATriangle = False
EndIf
‘Step 3: Determine Triangle Type
If IsATriangle Then
If (a = b) AND (b = c) Then
Output (“Equilateral”)
Else
If (a ≠ b) AND (a ≠ c) AND (b ≠ c) Then
Output (“Scalene”)
Else
Output (“Isosceles”)
EndIf
EndIf
Else
Output(“Not a Triangle”)
EndIf
End triangle3
4. One common addition to the triangle problem is to check for right triangles. Three sides constitute a right triangle if the Pythagorean relationship is satisfied: c2 = a2 + b2. This change makes it convenient to require that the sides be presented in increasing order, that is, a ≤ b ≤ c. Extend the Triangle3 program to include the right triangle feature. We will use this extension in later exercises.
1. Develop a decision table and additional test cases for the right triangle addition to the triangle problem (see Chapter 2 exercises). Note that there can be isosceles right triangles, but not with integer sides.
2. Develop a decision table for the “second try” of the NextDate function. At the end of a 31-day month, the day is always reset to 1. For all non-December months, the month is incremented; and for December, the month is reset to January, and the year is incremented.
M1 = {month: month has 30 days}
M2 = {month: month has 31 days}
M3 = {month: month is February}
D1 = {day: 1 ≤ day ≤ 28}
D2 = {day: day = 29}
D3 = {day: day = 30}
D4 = {day: day = 31}
Y1 = {year: year = 2000}
Y2 = {year: year is a non-century leap year}
Y3 = {year: year is a common year}
3. Develop a decision table for the YesterDate function (see Chapter 2 exercises).
4. Expand the commission problem to consider “violations” of the sales limits. Develop the corresponding decision tables and test cases.
A rifle salesperson in the former Arizona Territory sold rifle locks, stocks, and barrels made by a gunsmith in Missouri. Locks cost $45, stocks cost $30, and barrels cost $25. The salesperson had to sell at least one lock, one stock, and one barrel (but not necessarily one complete rifle) per month, and production limits were such that the most the salesperson could sell in a month was 70 locks, 80 stocks, and 90 barrels. After each town visit, the salesperson sent a telegram to the Missouri gunsmith with the number of locks, stocks, and barrels sold in that town. At the end of a month,
the salesperson sent a very short telegram showing –1 lock sold. The gunsmith then knew the sales for the month were complete and computed the salesperson’s commission as follows: 10% on sales up to (and including) $1000, 15% on the next $800, and 20% on any sales in excess of $1800.
The valid classes of the input variables are
L1 = {locks: 1 ≤ locks ≤ 70}
L2 = {locks = –1} (occurs if locks = –1 is used to control input iteration)
S1 = {stocks: 1 ≤ stocks ≤ 80}
B1 = {barrels: 1 ≤ barrels ≤ 90}
The corresponding invalid classes of the input variables are
L3 = {locks: locks = 0 OR locks < –1}
L4 = {locks: locks > 70}
S2 = {stocks: stocks < 1}
S3 = {stocks: stocks > 80}
B2 = {barrels: barrels < 1}
B3 = {barrels: barrels > 90}
5. Discuss how well decision table testing deals with the multiple fault assumption.
6. Develop decision table test cases for the time change problem (Chapter 6, problem 5).
5. The spring and fall changes between standard and daylight savings time create an interesting problem for telephone bills. In the spring, this switch occurs at 2:00 a.m. on a Sunday morning (late March, early April) when clocks are reset to 3:00 a.m. The symmetric change takes place usually on the last Sunday in October, when the clock changes from 2:59:59 back to 2:00:00. Develop equivalence classes for a long-distance telephone service function that bills calls using the following rate structure:
Call duration ≤20 minutes charged at $0.05 per minute or fraction of a minute
Call duration 20 minutes charged at $1.00 plus $0.10 per minute or fraction of a
minute in excess of 20 minutes.
Make these assumptions:
−− Chargeable time of a call begins when the called party answers, and ends when the
Calling party disconnects.
−− Call durations of seconds are rounded up to the next larger minute.
−− No call lasts more than 30 hours.
8. The retirement pension salary of a Michigan public school teacher is a percentage of the average of their last 3 years of teaching. Normally, the number of years of teaching service is the percentage multiplier. To encourage senior teachers to retire early, the Michigan legislature enacted the following incentive in May of 2010:
Teachers must apply for the incentive before June 11, 2010. Teachers who are currently eligible to retire (age ≥ 63 years) shall have a multiplier of 1.6% on their salary up to, and including, $90,000, and 1.5% on compensation in excess of $90,000. Teachers who meet the 80 total years of age plus years of teaching shall have a multiplier of 1.55% on their salary up to, and including, $90,000 and 1.5% on compensation in excess of $90,000.
Make a decision table to describe the retirement pension policy; be sure to consider the retirement eligibility criteria carefully. What are the compensation multipliers for a person who is currently 64 with 20 years of teaching whose salary is $95,000?
Chapter 8 Path Testing Exercises
1. Find the cyclomatic complexity of the graph in Figure 8.3.
2. Identify a set of basis paths for the graph in Figure 8.3.
3. Discuss McCabe’s concept of “flipping” decisions for nodes with outdegree ≥ 3.
4. Suppose we take Figure 8.3 as the DD-path graph of some program. Develop sets of paths (which would be test cases) for the C0, C1, and C2 metrics.
5. Develop multiple-condition coverage test cases for the pseudocode triangle program. (Pay attention to the dependency between statement fragments 14 and 16 with the expression (a = b) AND (b = c).)
6. Rewrite the program segment 14–20 such that the compound conditions are replaced by nested if–then–else statements. Compare the cyclomatic complexity of your program with that of the existing version.
14. If (a = b) AND (b = c)
15. Then Output (“Equilateral”)
16. Else If (a ≠ b) AND (a ≠ c) AND (b ≠ c)
17. Then Output (“Scalene”)
18. Else Output (“Isosceles”)
19. EndIf
20. EndIf
7. Look carefully at the original statement fragments 14–20. What happens with a test case (e.g., a = 3, b = 4, c = 3) in which a = c? The condition in line 14 uses the transitivity of equality to eliminate the a = c condition. Is this a problem?
8. The codeBasedTesting.xls Excel spreadsheet at the CRC website (www.crcpress.com/product/isbn/9781466560680 ) contains instrumented VBA implementations of the triangle, NextDate, and commission problems that you may have analyzed with the specBased-Testing.xls spreadsheet. The output shows the DD-path coverage of individual test cases and an indication of any faults revealed by a failing test case. Experiment with various sets of test cases to see if you can devise a set of test cases that has full DD-path coverage yet does not reveal the known faults.
9. (For mathematicians only.) For a set V to be a vector space, two operations (addition and scalar multiplication) must be defined for elements in the set. In addition, the following criteria must hold for all vectors x, y, and z ∈ V, and for all scalars k, l, 0, and 1:
a. If x, y ∈ V, the vector x + y ∈ V.
b. x + y = y + x.
c. (x + y) + z = x + (y + z).
d. There is a vector 0 ∈ V such that x + 0 = x
e. For any x ∈ V, there is a vector –x ∈ V such that x + (–x) = 0.
f. For any x ∈ V, the vector kx ∈ V, where k is a scalar constant.
g. k(x + y) = kx + ky.
h. (k + l)x = kx + lx.
i. k(lx) = (kl)x.
j. 1x = x.
How many of these 10 criteria hold for the “vector space” of paths in a program?