Kotlinlearncs.online LogoJava
Return to List

Test Writing: Map Sum Longer Than

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a method named sumLongerThan. sumLongerThan accepts a Map from String to Int as its first parameter and an Int as its second. It returns the sum as an Int of the values of all of the keys that are longer than the second parameter.

For example:

If the length is negative, you should throw an IllegalArgumentException.

As a reminder, you can iterate over the values in a map like this:

Test Design Challenge

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

  • Provide a public class named TestSummer 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 Kotlin's assert or check methods