Kotlinlearncs.online LogoJava
Return to List

Test Writing: Min Int

Created By: Geoffrey Challen
/ Version: 2021.3.0

Define a public class named Min which stores the minimum from a series of provided int values. Min should define a single public constructor that accepts an int that sets the initial value. You should also provide two other instance methods:

  1. add: accepts a single int and updates the minimum if necessary, but does not return a value
  2. min: returns the current minimum value

Once your class works correctly it should behave like this:

Your Min class should not expose any state publicly. You may also not store passed values in an array. This is incorrect and will prevent your class from recording the minimum of a large number of values!

Test Design Challenge

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

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