Spring 2026 — Assignment 2

Due 9-February-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.


[Total: 20 points]

Part 1: JUnit tests for CountWords (8 points)

Consider CountWords.java.

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

Grading rubric:

Reminder: do not modify the program under test


Part 2: JUnit Data-Driven Tests for Cal (8 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 a minimum, your tests must reach every line of code in the method.

Grading rubric:

Reminder: do not modify the program under test


Part 3: Analyze and fix a test flaw (4 points)

The Java method removeDuplicates() is supposed to remove all duplicate strings in the object. The following JUnit test method for removeDuplicates() has a flaw that is non-syntactic (that is, assume this test compiles and runs to completion).

In the test method, words is an instance of an object that stores strings in the order they are added and has methods add(), removeDuplicates(), getFirst(), getNext(), isFirst(), and isNext(), which do exactly what you would expect from their names. For example,

If words = "cookie cake cake pie"
removeDuplicates() removes the second "cake" from words
Thus, words = "cookie cake pie"

You can assume that the words variable has been properly instantiated, and the add(), getFirst(), getNext(), isFirst(), and isNext() methods have already been tested.

@Test
public void testRemoveDuplicates() 
{
   words.add("cookie");
   words.add("cake");
   words.add("cake");
   words.add("pie");
   words.removeDuplicates();
   assertTrue(words.getFirst().equals("cookie"));
}
  1. (2 points) Identify the flaw of the testRemoveDuplicates method and describe it in terms of the RIPR model. Be as precise, specific, and concise as you can. For full credit, you must use the terminology introduced in this course.
  2. (2 points) Explain how you would fix the test method. You may assume other methods are available on the object. You may rewrite the testRemoveDuplicates method or explain what the fix would be.

What to submit:

  1. Part 1:
    • Your JUnit test file (.java). Do not submit .class file We will download and run your JUnit tests.
      • (-8 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 tests 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.
      • (-8 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 tests 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 9-February 11am EST, by 10-February 11am EST)
(-10 points) for 48 hours late (submitted after 10-February 11am EST, by 11-February 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 CountWords.java
    • JUnit test file for Cal.java

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 © 2026 Upsorn Praphamontripong
Released under the Creative Commons License CC-BY-NC-SA 4.0 license.
Last updated 2026-02-01 18:24
  Top