Kotlinlearncs.online LogoJava
Return to List

Test Writing: Map Has Duplicate Values

Created By: Geoffrey Challen
/ Version: 2021.9.0

Write a method hasDuplicateValues that, given a Map<String, String>, returns true if the map contains duplicate values—meaning that two different keys map to the same value—and false otherwise. Recall that a map can never contain duplicate keys, since the second mapping from the same key overwrites the first.

You should use a Set to solve this problem! And as usual, maps, sets, and lists are all built-in to Kotlin and available for you to use to solve this problem.

Test Design Challenge

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

  • Provide a 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