Fall 2025 — Assignment 2

Due 22-September-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.


[Total: 20 points]

Part 1: JUnit tests for BoundedQueue (6 points)

Consider BoundedQueue.java.

Although we do not expect you to satisfy any specific test criterion, at minimum, your tests must reach every line of code in the method.

  1. Apply RIPR model to design tests for the BoundedQueue class.
    • The BoundedQueue class has several small methods.
    • Be sure to test every methods.
  2. Automate all tests you designed using JUnit
    • Run your tests and take a screenshot (or screenshots) showing the test results.
    • If the tests fail, analyze and briefly describe/discuss what causes the failure.

Reminder: do not modify the program under test


Part 2: JUnit Data-Driven Tests for Cal (4 points)

Consider Cal.java.

Apply RIPR model to design tests, develop JUnit data-driven tests for the cal() method. — the cal() method only. Do not develop tests for the main() and getN() methods. Since there is a precondition excluding basically all invalid inputs, you should test normal behavior only.

Although we do not expect you to satisfy any specific test criterion, at minimum, your tests must reach every line of code in the method.

Reminder: do not modify the program under test


Part 3: Analyze and design tests using RIPR model (10 points)

Consider the following Java class. PrimeNumbers has three methods.

public class PrimeNumbers implements Iterable<Integer>
{
   private List<Integer> primes = new ArrayList<Integer>();
   public void computePrimes(int n)
   {
      int count = 1;        // count of primes
      int number = 2;       // number tested for primeness
      boolean isPrime;      // is this number a prime

      while (count <= n)
      {
         isPrime = true;
         for (int divisor = 2; divisor <= number / 2; divisor++)
         {
            if (number % divisor == 0)
            {
               isPrime = false;
               break;      // for loop
            }
         }
         if (isPrime && (number % 10 != 9))        // FAULT
         {
            primes.add(number);
            count++; 
         }
         number++; 
      }
   }
   
   @Override public Iterator<Integer> iterator()
   {
      return primes.iterator();
   }
    
   @Override public String toString()
   {
      return primes.toString();
   }
}  

computePrimes() has a fault that causes it not to include prime numbers whose last digit is 9 (for example, it omits 19, 29, 59, 79, 89, 109, ...).

If possible, describe the following five tests. You can describe the tests as sequences of calls to the above methods, or briefly describe them in words. Be sure to include test input values and expected outputs. Note that the last two tests require the test oracle to be described.

  1. (2 points) A test that does not reach the fault
  2. (2 points) A test that reaches the fault, but does not infect
  3. (2 points) A test that infects the state, but does not propagate
  4. (2 points) A test that propagates, but does not reveal
  5. (2 points) A test that propagates and reveals the failure

If a test cannot be created, explain why.


What to submit:

  1. Part 1:
    • Your JUnit test file (.java). Do not submit .class file We will download and run your JUnit tests.
      • (-6 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.
    • A brief report including evidence that your JUnit tests ran, the results of running your tests, and a discussion of any that failed (The first two may be screenshots).
      • (-1 point) if no evidence showing the run and the results is provided
  2. Part 2:
    • Your JUnit test file (.java). Do not submit .class file We will download and run your JUnit tests.
      • (-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.
    • A brief report including evidence that your JUnit tests ran, the results of running your tests, and a discussion of any that failed (The first two may be screenshots).
      • (-1 point) if no evidence showing the run and the results is provided
  3. Part 3:
    • Written solutions to the questions
  4. If you collaborated, submit a brief collaboration summary: all partner names (refer to the collaborative options) and a summary of what each contributed.

(  -5 points) for 24 hours late (submitted after 22-September 11am EST, by 23-September 11am EST)
(-10 points) for 48 hours late (submitted after 23-September 11am EST, by 24-September 11am EST)

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


Submission

  1. Your report as a PDF file. Only typed PDFNo handwriting.  No hand-drawing.  No Word document.
  2. Your JUnit test files (.java)
    • JUnit test file for BoundedQueue.java
    • JUnit test file for Cal.java

Log in to Canvas, then upload your report as a PDF to Assignment2 on Gradescope. Make sure you connect your partner to your group on Gradescope so that everyone receives credit.

Each team submits only one copy.

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-09-14 19:24
  Top