Kotlinlearncs.online LogoJava
Return to List

Test Writing: List Unique Items

Created By: Geoffrey Challen
/ Version: 2021.9.0

Create a class Unique that provides a single class method uniqueItems. uniqueItems accepts a list of Objects and returns a count of how many of the objects in the list are unique, meaning that there are no other objects in the list that are equal to them. No items in the list will be null.

For example, given the list {1, 2, 4} you would return 3, whereas given the list {2, 2, 5} you would return 1. The list may contain any kind of Object. You may import collections like Maps or Sets for this problem, but they are not required.

Test Design Challenge

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

  • Provide a public class named TestUnique 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