Kotlinlearncs.online LogoJava
Return to List

Test Writing: Unique Counter

Created By: Geoffrey Challen
/ Version: 2020.11.0

Let's get more practice with maps! Create a class called UniqueCounter. You should provide two methods:

  1. add, which takes an Object and does not return a value
  2. get, which takes an Object and which returns an int.

get should return the number of times that add has been called for that Object on that UniqueCounter instance.

For example, which your class is done it should work like this:

We suggest that you use a Map internally to track the number of times you have seen a particular Object value.

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestUniqueCounter with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method