Fall 2025 — Assignment 4

Due 27-October-2025, 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: [2 points]  Drawing a graph

Consider the following Java method

/** 
* Description: Leet Code 771
* You're given strings jewels (representing the types of stones that are jewels) 
* and stones (representing the stones you have).
* Each character in stones is a type of stone you have.
* You want to know how many of the stones you have are also jewels.
* Letters are case sensitive, so "a" is a different type of stone from "A".
* 
* numJewelsInStones("aAb", "dbaaAbbcd") returns 6
* since there are 2 "a" and 1 "A" and 3 "b" in the string.
*/ 
public static int numJewelsInStones(String jewels, String stones) 
{
   var jewelSet = new HashSet<Character>();
   for (int i = 0; i < jewels.length(); i++) 
   {
      jewelSet.add(jewels.charAt(i));
   }
	  
   var count = 0;
   for (int i = 0; i < stones.length(); i++) 
   {
      if (jewelSet.contains(stones.charAt(i)))
         count += 1;
   }
      
   return count;
}  

Instructions:

(2 points) Draw a control flow graph (or graphs) representing the software under test. Annotate all line of code/code fragments. (no need for data-flow annotations).


Part 2: [6 points]  Structural-based coverage criterion

Consider the following Java method and the given graph (hw4.java)

/**
* This function parses a string s and returns a map containing the number
* of times each character occurred within the string.
*
* For example, if s = "testing"
* the frequencies method returns {s=1, t=2, e=1, g=1, i=1, n=1}
*/ 
public static Map<Character, Integer> frequencies(String s) 
{
   var map = new HashMap<Character, Integer>();
   
   for (int i = 0; i < s.length(); i++) 
   {
      Character c = s.charAt(i);      
      if (map.containsKey(c)) 
      {
         var currVal = map.get(c);
         map.put(c, currVal + 1);
      }
      else 
      {
         map.put(c, 1);
      }
   }
   return map;
} 

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.
    • Discuss any infeasible 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 5.

Part 3: [2 points]  Data-flow annotations

Instructions:

(2 points) Annotate the graph from Part 2 with definitions and uses (i.e., data-flow annotations).


Part 4: [6 points]  Data-flow coverage criterion

Consider the following Java method and the given graph (hw4.java)

/**
* @param array an array in ascending order
* @param value the value to search for
* @return the index of 'value' in 'array' else -1
*/ 
public static int binarySearch(int[] array, int value) 
{
   int left = 0;
   int right = array.length - 1;
      
   while (left <= right) 
   {
      int midIdx = (left + right) / 2;
         
      if (array[midIdx] > value) 
         right = midIdx - 1;
      else if (array[midIdx] < value) 
         left = midIdx + 1;
      else 
         return midIdx;
   }      
   return -1;
}   

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.
    • Discuss any infeasible requirements
  2. (2 points) Identify a set of test paths which fulfill your test requirements (from Part 4, question 1)
  3. (2 points) Design a set of test cases for each test path (from Part 4, 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 5.

Part 5: [4 points]  Test Automation

Do NOT modify the program under test.


Note that the Graph Coverage Web App and Data Flow Coverage Web App on the book web site will let you check (most of) your work. However, you should be able to apply the concept on a given software artifact without the tool.


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 27-October 11am EST, by 28-October 11am EST)
(-10 points) for 48 hours late (submitted after 28-October 11am EST, by 29-October 11am EST)

(-2 points) for submitting a Word document or handwriting, or a write-up that is not a typed PDF file.


Submission

Save your write-up as a PDF file (only typed PDF is acceptable) — No handwriting.  No Word document. Only the graphs may be hand-drawn neatly.

Submit your JUnit test file(s), .java (not a .class).

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.

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 © 2025 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2025-10-07 9:02
  Top