Spring 2026 — Assignment 4
Due 20-March-2026, 11am EST (before class)
Purpose:
- Understand graph-based testing and be able to apply graph coverage criteria to design tests
- Be able to analyze and determine the quality of the tests
- Practice test automation (using JUnit)
- Get ready for the final exam
All homeworks are due before class on the due date.
All homework assignments must reflect your own understanding of the topic
and be communicated in your own words.
You may use one of the
collaborative options.
You may also request help and advice from your classmates on Piazza.
Any help not allowed by that policy will be an honor violation.
Early-submission bonus points
Purpose: To encourage students to start working on the homework assignments early
and recognize students who are actively engaged in the content
You will receive
- 4% of the points you earn (from the assignment)
if you submit your assignment at least 48 hours early (submitted by 18-February-2026 11am EST).
- 2% of the points you earn (from the assignment)
if you submit your assignment at least 24 hours early (submitted after 18-February-2026 11am EST,
by 19-February-2026 11am EST).
Note:
The final submission timestamp shown on Gradescope will be used.
Part 1: [4 points] Drawing a Control Flow Graph
Consider the following Java method
public void doSomething(computeOps op, String strToReplace, String oldchar, String newchar)
{
revStr = "";
rsltStr = "";
rsltRepStr = "";
switch (op)
{
case ReverseNumber:
int revnum = 0;
while (numToReverse != null && numToReverse != 0)
{
revnum = revnum * 10;
revnum = revnum + (numToReverse % 10);
numToReverse = numToReverse / 10;
}
revStr = String.valueOf(revnum); // default value = 0, for simplicity
break;
case ComputePower:
rsltStr = String.valueOf( Math.pow(num1, num2) ); // default value = 1, for simplicity
break;
case FindLCM:
int gcf = 1;
for (int j=1; j<=num1 && j<=num2; j++)
{
// check if num1, num2, and num3 are divisible by j
if ( (num1 % j == 0) && (num2 % j == 0) )
gcf = j;
}
int lcm = (num1 * num2) / gcf;
rsltStr = String.valueOf(lcm); // default value = 0, for simplicity
break;
case ReplaceString:
// replace all occurrence of oldchar in str_to_replace with newchar
rsltRepStr = strToReplace.replace(oldchar, newchar);
break;
}
}
Instructions:
(4 points)
Draw a control flow graph representing the software under test (doSomething).
Annotate all lines of code, definitions, and uses (i.e., data-flow annotations).
- You may use any drawing software to draw your graph(s).
- Alternatively, you may draw your graph(s) by hand neatly,
take a screenshot/picture of your graph, and embed it in your report.
- If we cannot read your graph(s), we cannot assign points.
- Reminder:
ensure that your graph is syntactically and semantically valid.
Part 2: [6 points] Structural-based coverage criterion
Consider repeatedWords.java and the given graph
You will
apply graph-based testing to test all methods in the
repeatedWords class.
You may do unit-level testing or module-level testing.
Clearly specify in your report which level of your testing.
Do NOT modify the given Java source file.
The only exception is the package's name.
- If you organize your file(s) in a package, please update the package name to match yours.
- If you do not use a package, please comment or remove the
package package_name; line.
Instructions:
- (2 points) Given the above graph, design a set of test requirements which fulfills either
Edge coverage, Edge-pair coverage, or Prime path coverage.
- Clearly indicate in your write-up which criterion you selected —
Edge coverage, Edge-pair coverage, or Prime path coverage — do only one.
- Discuss any infeasible test requirements
- (2 points)
Identify a set of test paths which fulfill your test requirements (from Part 2, question 1)
- (2 points)
Design a set of test cases for each test path (from Part 2, question 2)
- Reminder:
A test case consists of input and expected output. Also include any relevant pre-state, post-state, or assumptions applicable to the problem.
- This will be one of two possible test sets you will implement in Part 4.
You
must use the allowable coverage criteria (above) only.
No points will be awarded for using any other coverage criterion.
Part 3: [6 points] Data-flow coverage criterion
Consider repeatedWords.java and the given graph
You will
apply graph-based testing to test all methods in the
repeatedWords class.
You may do unit-level testing or module-level testing.
Clearly specify in your report which level of your testing.
Do NOT modify the given Java source file.
The only exception is the package's name.
- If you organize your file(s) in a package, please update the package name to match yours.
- If you do not use a package, please comment or remove the
package package_name; line.
Note: There are edges/connections between graphs
(the couplings are also noted in part 2):
Coupling (repeat and checkDuples)
node 10 → node 13
node 14 → node 10
node 16 → node 10
node 17 → node 10
Coupling (repeat and checkDuples)
node 7 → node 13
node 14 → node 7
node 16 → node 7
node 17 → node 7
Coupling (repeat and isDelimit)
node 6 → node 18
node 22 → node 6
node 23 → node 6
Instructions:
- (2 points) Given the above graph,
design a set of test requirements which fulfills either
All-Uses coverage or All-du-paths coverage.
- Clearly specify in your write-up which criterion you selected —
All-Uses coverage or All-du-paths coverage — do only one.
- Discuss any infeasible test requirements
- (2 points)
Identify a set of test paths which fulfill your test requirements (from Part 3, question 1)
- (2 points)
Design a set of test cases for each test path (from Part 3, question 2)
- Reminder:
A test case consists of input and expected output. Also include any relevant pre-state, post-state, or assumptions applicable to the problem.
- This will be one of two possible test sets you will implement in Part 4.
You must use the allowable coverage criteria (above) only.
No points will be awarded for using any other coverage criterion.
Part 4: [4 points] Test Automation
- Decide which test set you will automate (a test set you designed in Part 2 or
a test set you designed in Part 3, automate only one test set)
- Make comments in your JUnit test file (.java file)
- Clearly specify which test set you automate (test set from Part 2 or test set from Part 3)
- Reminder: a test set is a collection of test cases.
For full credit, automate an entire set of test cases,
not just some test cases.
- For each JUnit test method, clearly identify which test case(s) it is for
- For grading purposes, the grader(s) must be able to map between the JUnit test methods
and the tests you designed.
- Demonstrate success by
- Submitting your JUnit tests (.java)
- A screen shot showing the result of execution (displaying the results of all tests).
- Embed the evidence showing the result in the your write-up.
- By default, we will download and run your JUnit test file
against the program under test (the original version posted for this assignment).
Thus, it is important that you do not modify the program under test (except the package's name).
- Grading for this part will be based on:
- The number of test cases (i.e., reflecting the test requirements) you automate
- The quality of your test code
- The quality of comments in your test file
- Note:
- (-4 points) If your submission does not include your JUnit test file (.java)
or if your JUnit test file does not compile or does not run.
Do not submit .class file(s).
- (-1 point) If your submission does not include the evidence demonstrating the result of execution;
be sure that the evidence shows the results of all tests.
Do NOT modify the program under test.
Grading Rubric
[Total: 20 points]
Complete the tasks. Provide correct and clear solutions. Properly document your solutions.
( -5 points) for 24 hours late (submitted after 20-March 11am EST, by 21-March 11am EST)
(-10 points) for 48 hours late (submitted after 21-March 11am EST, by 22-March 11am EST)
(-2 points) for submitting a Word document or handwriting, or a write-up that is not a typed PDF file.
Only a neatly hand-drawn graph is allowed (for part 1).
Submission
- Your write-up
- Save your write-up as a PDF file (only typed PDF is accepted)
— No handwriting. No Word document.
- Exception for assignment 4: a neatly hand-drawn graph is allowed (for part 1).
- Your JUnit test file and evidence(s)
- A .java file, not a .class file.
By default, we will download, compile, and run your test file.
- (-4 points) if your JUnit test file (.java) is missing or inaccessible,
does not open, does not compile, or does not run.
Thus, be sure to verify that your JUnit .java file is accessible, compiles, and runs.
- Evidence(s) or screenshot(s) showing the results of running your tests.
Be sure to show the result of each test and
a discussion of any tests that failed.
- (-1 point) if no evidence showing the run and the results is provided
Each team submits only one copy.
Upload your report as a PDF and your JUnit test file(s) (.java) to Assignment 4 on Gradescope.
Make sure you connect your partner to your group on Gradescope so that everyone receives credit.
Make sure that you submit all file(s).
Verify that you submit the correct file(s).
Making your submission available to instructor and course staff is your
responsibility;
if we cannot access or open your file, you will not get credit.
Be sure to test access to your file before the due date.
Copyright © 2026 Upsorn Praphamontripong
Released under the
CC-BY-NC-SA 4.0 license.
Last updated 2026-02-26 19:40