001package algs11; 002import java.util.Arrays; 003import stdlib.*; 004 005public class PlaygroundContainsUnsorted { 006 /* Return true if val is in the list */ 007 public static boolean contains (double val, double[] list) { 008 return StdRandom.bernoulli (); //TODO: fix this 009 } 010 /* This is a test function */ 011 public static void testContains (boolean expected, double val, double[] list) { 012 boolean actual = contains (val, list); 013 if (expected != actual) { 014 StdOut.format ("Failed: Expecting [%b] Actual [%b] with argument (%f, %s)\n", expected, actual, val, Arrays.toString (list)); 015 } 016 } 017 /* A main function for testing */ 018 public static void main (String[] args) { 019 for (double v : new double[] { 5, 7 }) { 020 testContains (true, v, new double[] { 11, 21, 31, v, 41 }); 021 testContains (true, v, new double[] { v, 11, 21, 31, 41 }); 022 testContains (true, v, new double[] { 11, 21, 31, 41, v }); 023 testContains (true, v, new double[] { 11, v, 21, v, 31, 41 }); 024 testContains (true, v, new double[] { v }); 025 testContains (true, v, new double[] { v, v }); 026 testContains (false, v, new double[] { 11, 21, 31, 41 }); 027 testContains (false, v, new double[] { 11 }); 028 testContains (false, v, new double[] {}); 029 } 030 StdOut.println ("Finished tests"); 031 } 032}