Empirical Testing - leortyz/softwareEngineeringResources GitHub Wiki
Objectives
- Test the program freely using intuitive test cases.
Requirements
- Eclipse IDE for Java Developers >= 2021β03 Download from Eclipse || Get executable
- Git
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:
- If all three sides are equal, the program output is Equilateral.
- If exactly one pair of sides is equal, the program output is Isosceles.
- If no pair of sides is equal, the program output is Scalene.
- 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:
- Complete the table with tests and assumptions you consider necessary.
- 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
- Document your test cases and assumptions.
- 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 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©ββββββββ