Empirical Testing - leortyz/softwareEngineeringResources GitHub Wiki

Objectives

  • Test the program freely using intuitive test cases.

Requirements

Introduction

The triangle problem is the most widely used example in software testing literature. The logic used for the problem is clear but complex, meaning that behind some intuitive conditions are other hidden ones more difficult to get. The traditional problem states the following: the triangle program accepts three integers, a, b, and c, as input. These are taken to be sides of a triangle. The output of the program is the type of triangle determined by the three sides: Equilateral, Isosceles, Scalene, or Not Triangle. [1] To start, it is important to define what a triangle is. Let us see some definitions and compare them with yours:

  • A closed plane figure having three sides and three angles.
  • A polygon having three sides.
  • A triangle is a polygon with three edges and three vertices.

These definitions describe what it is explicitly seen by a person, not what mathematical/ geometrical implications and theorems really define a triangle. Here is where this simple problem turns into a difficult and complex task. Not because of triangle’s properties and rules, but the assumptions the problem does. One assumption is that developers know some details about triangles, particularly the triangle inequality theorem: the sum of any pair of sides must be strictly greater than the third side. Here is an improved version of the problem and the one we will use during the lab [1]: The triangle program accepts three integers, a, b, and c, as input. These are taken to be sides of a triangle. The integers a, b, and c must satisfy the following conditions:

  • 1 ≀ a ≀ 200.
  • 1 ≀ c ≀ 200
  • 1 ≀ b ≀ 200
  • b < a + c
  • a < b + c
  • c < a + b

The output of the program is the type of triangle determined by the three sides: Equilateral, Isosceles, Scalene, or Not Triangle. If an input value fails any of conditions c1, c2, or c3, the program notes this with an output message, for example, β€œValue of b is not in the range of permitted values.” If values of a, b, and c satisfy conditions c4, c5, and c6, one of four mutually exclusive outputs is given:

  1. If all three sides are equal, the program output is Equilateral.
  2. If exactly one pair of sides is equal, the program output is Isosceles.
  3. If no pair of sides is equal, the program output is Scalene.
  4. If any of conditions c4, c5, and c6 is not met, the program output is Not Triangle.

Development

Create a Java program that solves the triangle problem, fulfilling all the conditions involved. Below, a pseudocode that you can use to create your program:

Program triangle
Dim a, b, c As Integer
Dim c1, c2, c3, Is Triangle 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 ≀ 200)   
	c2 = (1 ≀ b) AND (b ≀ 200)    
	c3 = (1 ≀ c) AND (c ≀ 200)    
	If NOT(c1)
		Then Output (β€œValue of a is not in the range of permitted values”)    
	End If
	If NOT(c2)
		Then Output (β€œValue of b is not in the range of permitted values”)
	End If    
	If NOT(c3)
		Then Output (β€œValue of c is not in the range of permitted values”)    
	End If
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 Is Triangle = True   	
	Else Is Triangle = False
End If

Step 3: Determine Triangle Type
If Is Triangle    
	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”) 
		End If         
	End If    
	Else Output (β€œNot a Triangle”)
End If
End triangle

After writing your code, it is time to test whether it behaves correctly. To do this, you should write certain combinations of inputs and expected outputs. This must be done without using your code; you must produce a table like the one presented below. To do it, you must use the requirements of the problem, your assumptions as well as your experience and knowledge.

╔══════╦════════════════════════╦═════════════════╗
β•‘ Test β•‘ Input Values (a, b, c) β•‘ Expected Output β•‘
╠══════╬════════════════════════╬═════════════════╣
β•‘   1  β•‘        3, 3, 3         β•‘   Equilateral   β•‘
╠══════╬════════════════════════╬═════════════════╣
β•‘   2  β•‘        4, 5, β€œ?”       β•‘  Invalid Input  β•‘
β•šβ•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Assumptions are critical to test planning, since the set of test cases needed to test the behavior of the program will vary based on the assumptions you made. Assumptions need to be documented. The most dangerous assumptions are those which are not documented but which are simply assumed to be true.

For example: 
	Assumption:
	Non numerical values are invalid, i.e. β€œA” or β€œ?”

For this lab, you must:

  1. Complete the table with tests and assumptions you consider necessary.
  2. Implement the tests into your code. For example: Suppose you created a method called β€œtriangleType” that receives 3 integers and returns a string with the type of the triangle. To test if the output is correct based on your test cases, do the following:
System.out.println(β€œTest 1: ”+ β€œEquilateral”.equals(triangleType(3,3,3)));
System.out.println(β€œTest 2: ”+ β€œInvalid Input”.equals(triangleType(4,5,’?’)));

If any of yours tests fails, create a new java class, copy your code, and modify it so that it behaves according to your test cases.

Deliverables

  1. Document your test cases and assumptions.
  2. URL of the repository where you performed the lab.

Rubric

╔════════════════════════════════════════════════════════════════════╦═══════╗
β•‘ Description                                                        β•‘ Value β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Project code (in a repository)                                     β•‘   50  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Test cases and assumptions                                         β•‘   50  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Penalty per hour or fraction of delay                              β•‘  -30  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Penalty for not uploading required deliverables as specified       β•‘  -30  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•

References

  • 01 Software Testing: A Craftsman’s Approach, Fourth Edition
  • 02 Tringle Definition
  • 03 The Problem Analysis Triangle