Lab9
Lab9
# If there are points with the same y-coordinate, choose the one with the minimum
x-coordinate
for i in range(len(p)):
if p[i].y == p[min_idx].y and p[i].x > p[min_idx].x:
min_idx = i
a. Statement Coverage.
b. Branch Coverage.
Test Case 1:
● Input Points:
Point(2,3),Point(1,2),Point(3,1)
● Purpose:
This test case is designed to ensure that all statements in the flow graph are
executed at least once.
Test Case 1:
● Input Points:
Point(2,3),Point(1,2),Point(3,1)
● Purpose:
This test case ensures that both branches (True/False) of the conditional
statements are tested at least once.
Test Case 2:
● Input Points:
Point(3,3),Point(4,3),Point(5,3)
● Purpose:
This test case ensures that both branches (False/False) of the conditional
statements are tested.
Test Case 1:
● Input Points:
Point(2,3),Point(1,2),Point(3,1)
Purpose:
This test case ensures that the condition p[i].y < p[min_idx].y is
evaluated as True.
Test Case 2:
● Input Points:
Point(1,3),Point(2,3),Point(3,3)
● Purpose:
This test case ensures that the condition p[i].y < p[min_idx].y is
evaluated as False.
Test Case 3:
● Input Points:
Point(2,2),Point(1,2),Point(3,2)
● Purpose:
This test case ensures that both conditions p[i].y == p[min_idx].y and
p[i].x < p[min_idx].x are evaluated as True.
Test Case 4:
● Input Points:
Point(3,2),Point(4,2),Point(2,2)
● Purpose:
This test case ensures that the condition p[i].y == p[min_idx].y is
True and the condition p[i].x < p[min_idx].x is False.
Output :
3.For the test set you have just checked can you find a mutation of
the code (i.e. the deletion, change or insertion of some code) that will
result in failure but is not detected by your test set. You have to
use the mutation testing tool
a. Deletion Mutation:
Original Code:
min = i;
min = i;
→ The deletion mutation removes the condition check, causing min = i to execute
unconditionally. While statement coverage is still satisfied (since min = i is
executed), the mutation may go undetected if the test cases do not verify the
correctness of the minimum value selection, potentially leading to incorrect results
without triggering a failure.
b. Change Mutation:
Original Code:
Mutated Code:
This change could impact how the algorithm behaves, particularly if y values are
equal for multiple points. The updated condition could now include cases where y
values are equal, potentially resulting in a different behavior (such as including equal
y values in the logic).
c. Insertion Mutation:
Original Code
min = i;
Mutated Code:
min = i + 1;
→ Effect of Mutation:
● Failure to Detect the Issue: If tests focus only on whether min is assigned a
value and don't verify the correctness of the index, they may fail to catch the
problem. Tests that don't check the correctness of the assignment may
overlook this error.
3. Create a test set that satisfies the path coverage criterion
where every loop is explored at least zero, one or two times.
Test:
● Expected Result:
Since the vector has zero elements (p.size() == 0), the loop will not
execute. The method should return immediately without any processing. This
covers the scenario where the loop is not executed at all.
Test:
● Expected Result:
The vector has only one point (p.size() == 1), so the loop will be skipped.
The method should perform no swapping. The point will remain in the same
position, effectively leaving the vector unchanged. This test case covers the
scenario where the loop iterates zero times but checks the condition for a
single element.
● Input: A vector with two points where the first point has a higher y-coordinate
than the second.
Test:
● Expected Result:
The loop will iterate once, comparing the first and second points:
○ The first point ((1,1)) has a higher y-coordinate than the second point
((0,0)), so the loop will perform a swap.
○ The vector will now be [ (0, 0), (1, 1)]. This test case checks
the loop's behavior when it iterates once, performing a swap.
Test Case 4: Loop Explored More Than Twice (Loop Iterates Over Multiple
Points)
Test:
● Expected Result:
The loop will iterate through all three points:
1. First iteration: The first point (2, 2) is compared with (1, 0):
■ Since (1, 0) has a lower y-coordinate, the minY will be
updated, and a swap will occur, moving (1, 0) to the front.
2. Second iteration: The newly swapped first point (1, 0) will be
compared with (0, 3).
■ Since (1, 0) has a lower y-coordinate than (0, 3), no further
swap will be needed, as minY remains at index 1.
● The final vector will be [ (1, 0), (2, 2), (0, 3)]. This case ensures
the loop iterates through multiple points and performs at least one swap.
Lab Execution:-
Q1). After generating the control flow graph, check whether your CFG
matches with the CFG generated by Control Flow Graph Factory Tool
and Eclipse flow graph generator.
Q2). Devise minimum number of test cases required to cover the code
using the aforementioned criteria.