Kotlinlearncs.online LogoJava
Return to List

Test Writing: Number Of Sum Combinations

Created By: Rohith Sanjay
/ Version: 2024.8.0

Write a method numberOfSumCombinations that takes in three arguments: an array of ints called first, an array of ints called second, and an int number called target. This method must return the number of ways (as an int) that target can be obtained by summing a value from the first array with a value from the second array. For example: given that first = [1, 2, 3, 4, 5], second = [6, 7, 8, 9, 10], and target = 10, numberOfSumCombinations will return 4 because the target (10) can be summed in 4 ways (by adding one value from first and one value from second): 1+9, 2+8, 3+7, and 4+6. Note #1: A valid combination is a sum of two elements: the first element must be from the first array, and the second element must be from the second array. Note #2: The two array arguments are guaranteed to be the same size. Note #3: It's recommended to use a nested for loop to solve this problem.

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
Report a Problem

Attribution must link to this page: https://www.learncs.online/testtesting/java/number-of-sum-combinations/[email protected]