Kotlinlearncs.online LogoJava
Return to List

Test Writing: Check Top Ten Movies

Created By: Ayesha Ahmed
/ Version: 2023.7.0

You asked all your friends to rank a list of 10 movies that you gave them, from 0 for the best to 9 for the worst. (Because you're a computer scientist, you always number starting at zero!)

Let's write a method to ensure that the array of rankings provided by each of your friends is valid. To be valid, the IntArray? needs to not be null, have 10 elements, and contain all Int values from 0 to 9, inclusive. However, the values in the array can be in any order! So the array {1, 7, 5, 2, 3, 9, 0, 6, 4, 8} is valid.

Create a method named checkTopTenList that accepts an IntArray? and returns true if it is a valid top ten list according to the rules above, and false otherwise. Do not modify the contents of the passed array, since if you do how will you remember what your friend picked? Note that there are several ways to approach this problem that will work.

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