Kotlinlearncs.online LogoJava
Return to List

Test Writing: Array Double Upper

Created By: Chris Taylor
/ Version: 2023.7.0

Write the recursive method, arrayDoubleUpper, that accepts two arguments and, when called by the provided arrayDoubleUpper(int[] nums) method, returns the same array of ints where each int in the returned array is double the value of the original element. You may assume that the array passed is not null.

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
int[] arrayDoubleUpper(int[] nums, int index) {
return null; // You may need to remove this starter code
}
/**
* Returns the array with all the elements containing twice the value of the original elements.
*
* @param nums The integers to be doubled
* @return The integers that have been doubled
*/
int[] arrayDoubleUpper(int[] nums) {
return arrayDoubleUpper(nums, 0);
}