Kotlinlearncs.online LogoJava
Return to List

Test Writing: Find Double; Ignore Diagonals

Created By: Rohith Sanjay
/ Version: 2024.8.0

Write a method findDouble that takes in 2 arguments: the first argument is a 2D array of doubles called values, and the second argument is a double called target. Your method will return the target number if it exists in a non-diagonal element of values, or return -1.0 otherwise (if values does NOT contain target in a non-diagonal element). You may assume the values array will always be square (same number of rows as columns). If values is null or empty, return -1.0. Examples: If values = [[1.0, 2.0], [3.0, 4.0]] and target = 2.0, then findDouble returns 2.0. If values = [[3.0]] and target = 3.0, then findDouble returns -1.0 because target is in a diagonal element (even though it is present in values).

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/find-double-ignore-diagonals/[email protected]