Kotlinlearncs.online LogoJava
Return to List

Test Writing: String Doubled

Created By: Geoffrey Challen
/ Version: 2020.9.0

Write a function called doubleString. Given a String "test", you should return "tteesstt". Given "HaHa!" you should return "HHaaHHaa!!". Given the String "" you should return "". Given the null String return null.

There are several ways to approach this problem, and you may want to look into either the toCharArray String methods or Kotlin string indexing. For example, if var test = "Test", then test[0] is "T" and test[2] is "s".

Keep in mind that adding two characters together will be done mathematically. So, given a character 'x', if you want String concatenation you need to do x + "" + x.

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