0% found this document useful (0 votes)
5 views7 pages

A2 Testing & Measure

Uploaded by

202111238
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

A2 Testing & Measure

Uploaded by

202111238
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

College of Engineering

Assignment 2. Fall Semester 2024

Course Title Software Measurement and Testing

Course Code 0103440

Due Date: Thursday 17 October 2024 at 11 am


Student Name Adel Al-Khaldi

Student I.D 202111238

Studen
Part CLO Question Score Comment
t Score

1 4 5
Total
5

Your solution should be submitted electronically on Moodle (Word file


format). Late submissions will be penalized (10%). Assignments can be
submitted up to 24 hours after the deadline. Cheated solutions will be
assigned zero grade.

1
Part 1:
Consider the code of the method:
determineTriangleType(double a, double b, double c)
in Page 4. This method determines the type of a triangle based on the
lengths of its sides.
a. Draw a control flow graph for the program and clearly label each node
to show its correspondence to a statement.
b. Calculate the program’s cyclomatic complexity. What does this mean in
terms of the number of test cases to cover the code with respect to its
branches?
c. Develop a set of test cases to achieve full decision coverage.
d. Using JUnit, define and execute all test cases in part c.
For each test case, you must provide the input values and the expected
output in addition to the covered path. Fill the following table:

Test Input Expected Actual Test Case Path Covered


Case Values Outputs Outputs Result
Identifier (Pass/
Fail)

On Moodle, submit this Word file including your answers to parts a-d
above. In addition, upload the Java test file for part d.
The requirements are given as follows:
Functional Requirements
Input Requirements:
The program shall accept three positive numerical inputs representing the
lengths of the sides of a triangle (a, b, and c).

2
The inputs shall be double-precision floating-point numbers.

Validation Requirements:
The program shall validate that none of the input lengths (a, b, c) are less
than or equal to zero. If any input is invalid, the program shall return a
message indicating that the sides cannot be less than or equal to zero.
The program shall check that the sum of the lengths of any two sides is
greater than the length of the third side (triangle inequality theorem). If
this condition is not met, the program shall return a message indicating a
triangle inequality violation.
Triangle Classification Requirements:
The program shall determine and classify the triangle based on the lengths
of its sides into one of the following categories:
Equilateral triangle: All three sides are equal.
Isosceles triangle: Exactly two sides are equal.
Scalene triangle: All three sides are different.
Right triangle: A triangle that satisfies the Pythagorean theorem (only
applicable filtering to other classifications).
If the input does not meet the criteria for being a triangle, it shall classify
the input as "Not a triangle".
Output Requirements:
The program shall return a string output indicating the type of triangle, or
an appropriate error message based on the input validation.

3
private static boolean isRightTriangle(double a, double b, double c) {
// Check if the triangle is right-angled
return (Math.abs(a * a + b * b - c * c) < 1e-10 ||
Math.abs(a * a + c * c - b * b) < 1e-10 ||
Math.abs(b * b + c * c - a * a) < 1e-10);
}

4
a.) Control Flow Graph

b.) Equations for Cyclomatic Complexity:

V(g)= P + 1, where P is a number of decisions (such as if statements in this case)


V(g)= 5 + 1 = 6
V(g)= E - N + 2P, where E is Edges, N is nodes, P number of connected modules
V(g)= 10 - 6 + 2(1) = 6

The diagram has the Cyclomatic Complexity of 6, meaning there is a minimum of 6


paths to ensure full coverage of edges and nodes, requiring 6 Different test cases to
cycle through all different paths.
5
C.)

Test Input Expected Actual Test Path Covered


Case Values Outputs Outputs Case
Identifier Result
(Pass/
Fail)

T1 (0,4,5) Not a triangle Not a Pass 2-R


(sides cannot triangle
be less than (sides
or equal to cannot be
zero) less than or
equal to
zero)

T2 (3,4,8) Not a triangle Not a Pass 2-6-R


(triangle triangle
inequality (triangle
violation) inequality
violation)

T3 (3,4,5) Right Triangle Right Pass 2-6-10-14-18-R


Triangle

T4 (7,8,9) Scalene Scalene Pass 2-6-10-14-18-R


Triangle Triangle

T5 (3,3,3) Equilateral Equilateral Pass 2-6-10-R


Triangle Triangle

T6 (5,5,7) Isosceles Isosceles Pass 2-6-10-14-R


Triangle Triangle

D.)
**The file has been uploaded and this is a screenshot of the JUnit Running
the tests**

6
7

You might also like