Kotlinlearncs.online LogoJava
Return to List

Test Writing: Invert a Map

Created By: Geoffrey Challen
/ Version: 2020.10.0

Create a method named invert. invert should accept a Map<String, Int> and return a Map<Int, String> with all of the key-value pairs swapped.

Because values are not necessarily unique in a map, normally you would need a way to determine what the right approach is when two keys map to the same value. However, the maps passed to your function will not have any duplicate values.

Test Design Challenge

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

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