Fall 2026 — Assignment 1

Due 21-September-2026, 1pm
Purpose:

All homework assignments 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 as long as the help/advice follows the course's collaborative policy. 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. No extension/exception on the early submission bonus points.


[Total: 20 points]

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

Consider the following Java class. PrimeNumbers.java has three methods.

  • computePrimes(), takes one integer input and computes that many prime numbers.
  • iterator() returns an Iterator that will iterate through the primes
  • toString() returns a string representation
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: For the last two tests, in addition to the test input values and the corresponding expected outputs, you are required to describe the test oracle. You may describe them in words or as JUnit assertion statements.

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

[Reminder: Two mandatory components of each test case: input value(s) and expected output — point(s) will always be deducted if any of these is missing]

If a test cannot be created, explain why.


Part 2: Develop JUnit tests (5 points)

Use PrimeNumbers.java from part 1.

Develop JUnit tests for the computePrimes() method.

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.

For each test, include comments (directly in your JUnit test file) that specify

  • The purpose of the test
  • Which part(s) of your automated tests address observability, if applicable
  • Which part(s) of your automated tests address controllability, if applicable

Your JUnit tests must include the two tests you designed in part 1

  • The test you designed for question 4 (not reveal the fault)
  • The test you designed for question 5 (reveal the fault)

Do NOT modify or refactor 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.

Run your tests and take a screenshot showing the test results. You will later include the screenshot in your report.

If the tests fail, analyze and briefly describe/discuss what causes the failure.


Part 3: JUnit Data-Driven Tests for the computeRangeSum() method (5 points)

Consider the computeRangeSum() method of someOps.java.

Note: There exists a fault in the subject under test. At least one of your tests must detect it.

Do NOT modify or refactor 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.

Apply RIPR model to design tests, develop JUnit data-driven tests for the computeRangeSum() method.

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.

You are required to develop JUnit data-driven tests.

  • No points will be awarded for non-data-driven tests.

Run your tests and take a screenshot showing the test results. You will later include the screenshot in your report.

If the tests fail, analyze and briefly describe/discuss what causes the failure.


What to submit:

  1. Part 1:
    • Written solutions to the questions
    • Save your report as a PDF file
  2. Part 2:
    • Your JUnit test file (.java). Do not submit .class file We will download and run your JUnit test file.
      • (-5 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.
    • In your report, include 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:
    • Your JUnit test file (.java). Do not submit .class file We will download and run your JUnit test file.
      • (-5 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.
    • In your report, include 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
  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 21-September 1pm, by 22-September 1pm)
(-10 points) for 48 hours late (submitted after 22-September 1pm, by 23-September 1pm)

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


Submission

Save your assignment as a PDF file. — No handwriting.  No hand-drawing.  No Word document.

Log in to Canvas, then upload your report as a PDF to Assignment1 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 © 2026 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2026-09-02 14:37
  Top