Kotlinlearncs.online LogoJava
Return to List

Test Writing: String Rotate Left

Created By: Geoffrey Challen
/ Version: 2020.9.0

This problem combines Strings, functions, and arrays. Super fun!

Write a function called rotateLeft that takes a String as its first argument and a non-negative Int as its second argument and rotates the String left by the given number of characters. Here's what we mean by rotate:

  • CS125 rotated left by 1 becomes S125C
  • CS125 rotated left by 2 becomes 125CS
  • CS125 rotated left by 3 becomes 25CS1

And so on. Notice how characters rotated off the left end of the String wrap around to the right. This problem is similar to one that you have done before, but has a new wrinkle.

If the passed String argument is null, you should return null. Good luck and have fun!

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