Kotlinlearncs.online LogoJava
Return to List

Test Writing: Count Repeated Words With Map Case-Insensitive

Created By: Pranav Narayanan
/ Version: 2025.2.1

Declare and complete a method named countRepeatedWords that, given a List<String>, returns a count of how many Strings appear more than once in the List as an int. You should complete this problem with a Map, and not use a nested loop.

For example, given the list {"one", "two", "four"}, you would return 0, since no words appear more than once. Given the list {"two", "two", "five"}, you would return 1.

This should be a case-insensitive comparison. For example, given the list {"two", "TwO", "five"}, you would return 1, since "two" and "TwO" are the same when being case-insensitive.

Adapted from Count Repeated Words HW 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
Report a Problem

Attribution must link to this page: https://www.learncs.online/testtesting/kotlin/count-repeated-words-with-map-case-insensitive/[email protected]