Kotlinlearncs.online LogoJava
Return to List

Test Writing: Array All Pairs

Created By: Geoffrey Challen
/ Version: 2022.1.0

Write a method arrayAllPairs that returns whether a passed int[] array is composed entirely of adjacent pairs of the same value. For example, the array {1, 1, 2, 2} and the array {4, 4, -1, -1} are composed of adjacent pairs of the same element, but {2, 1, 1, 2} and {4, 4, -1, 0} are not. To be composed entirely of pairs of the same element, the array must contain an even number of elements. If the passed array is empty, you should return false.

You will need to construct your loop carefully to complete this problem! We suggest that you examine the array looking for a counterexample: meaning a pair of adjacent elements that do not have the same value.

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 Java's assert method