Spring 2026 — Assignment 4

Due 20-March-2026, 11am EST (before class)
Purpose:

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

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).


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.

Instructions:

  1. (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. (2 points) Identify a set of test paths which fulfill your test requirements (from Part 2, question 1)
  3. (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.

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:

  1. (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. (2 points) Identify a set of test paths which fulfill your test requirements (from Part 3, question 1)
  3. (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

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

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 Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2026-02-26 19:40
  Top