Kotlinlearncs.online LogoJava
Return to List

Test Writing: Invert a Map

Created By: Geoffrey Challen
/ Version: 2020.10.0

Create a public class called Inverter with a single class method named invert. invert should accept a Map<String, Integer> and return a Map<Integer, String> with all of the key-value pairs swapped.

You can assert that the passed map is not null.

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 Java's assert method