Professional Documents
Culture Documents
I2SE Homework 9
I2SE Homework 9
Homework 9
Vakhtang Pheradze
1)
a)
40: return 1;
50: factorial *= n;
60: n--;
80: go to 50
b)
Statement Coverage:
To achieve statement coverage, we need to ensure that every statement in the code is executed at
least once.
Branch Coverage:
This covers the branch where n >= 0, and the loop is executed.
Paths Traversed:
For path coverage, we need to consider different paths through the code. The paths are outlined
below:
Throws an exception.
c)
Certainly, here's a rewritten version:
Obtaining complete path coverage for code containing loops poses a formidable challenge due to the
exponential increase in possible paths with each additional loop iteration. For instance, when the
loop runs multiple times, attempting to cover paths with 0, 1, 2, and 3 iterations becomes
impractical, leading to an exhaustive number of test cases.
In real-world scenarios, a pragmatic approach often involves prioritizing statement coverage and
branch coverage. These metrics strike a balance between testing thoroughness and feasibility. By
ensuring the execution of each statement and taking each branch at least once, one can attain
confidence in the fundamental functionality and logic of the code.
2)
a) Equivalence Classes and Representatives:
- Representative: "Hello"
- Description: This class includes strings where the length is less than or equal to maxWidth. The
function should return the input string unchanged.
- Description: This class includes strings where the length is greater than maxWidth. The function
should abbreviate these strings to a length of maxWidth - 3 by appending "..." to the end.
3. maxWidth < 4:
- Representative: 3
- Description: This class includes cases where maxWidth is less than 4. The function should throw an
IllegalArgumentException.
b) Boundary Values:
- Minimum: 0
- Maximum: 3
3)