001package algs11;
002import java.util.Arrays;
003import stdlib.*;
004
005public class PlaygroundContainsSorted {
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    testContains (true, 11, new double[] { 11, 21, 31, 41, 51, 61, 71 });
020    testContains (true, 21, new double[] { 11, 21, 31, 41, 51, 61, 71 });
021    testContains (true, 31, new double[] { 11, 21, 31, 41, 51, 61, 71 });
022    testContains (true, 41, new double[] { 11, 21, 31, 41, 51, 61, 71 });
023    testContains (true, 51, new double[] { 11, 21, 31, 41, 51, 61, 71 });
024    testContains (true, 61, new double[] { 11, 21, 31, 41, 51, 61, 71 });
025    testContains (true, 71, new double[] { 11, 21, 31, 41, 51, 61, 71 });
026    testContains (false, 10, new double[] { 11, 21, 31, 41, 51, 61, 71 });
027    testContains (false, 20, new double[] { 11, 21, 31, 41, 51, 61, 71 });
028    testContains (false, 30, new double[] { 11, 21, 31, 41, 51, 61, 71 });
029    testContains (false, 40, new double[] { 11, 21, 31, 41, 51, 61, 71 });
030    testContains (false, 50, new double[] { 11, 21, 31, 41, 51, 61, 71 });
031    testContains (false, 60, new double[] { 11, 21, 31, 41, 51, 61, 71 });
032    testContains (false, 70, new double[] { 11, 21, 31, 41, 51, 61, 71 });
033    testContains (false, 80, new double[] { 11, 21, 31, 41, 51, 61, 71 });        
034    StdOut.println ("Finished tests");
035  }
036}