i don't understand how following unit test (from textbook) adequately tests java's math.min()
method:
import java.util.random; /** app tests method min of class math. */ public class mathtester { public static void main (string[] args) { final int vector_size = 100; random random = new random(); boolean pass = true; (int = 0; < vector_size && pass; i++) { int = random.nextint(); int b = random.nextint(); double min = math.min(a, b); if (a < min || b < min && (a != min && b != min)) { system.out.print("the method failed test case: "); system.out.println("a = " + + ", b = " + b); pass = false; } } if (pass) { system.out.println("the method passed test cases"); } } }
suppose a == 5
, b == 3
, , min == 2
. should generate failure because math.min()
supposed return lesser of arguments (and 2 not argument). yet seems me test (wrongly) pass case because a
, b
both greater 2, therefore if
block, contains fail code, not execute.