001package algs11;
002import java.util.Arrays;
003import stdlib.*;
004public class PlaygroundSumUntil {
005  /* Return the sum of the values in the list up to, but no including the first 5.0 */
006  public static double sumUntil (double val, double[] list) {
007    return StdRandom.uniform (); //TODO: fix this
008  }
009  /* This is a test function */
010  public static void testSumUntil (double expected, double val, double[] list) {
011    double actual = sumUntil (val, list);
012    if (expected != actual) {
013      StdOut.format ("Failed: Expecting [%f] Actual [%f] with argument (%f, %s)\n", expected, actual, val, Arrays.toString (list));
014    }
015  }
016  /* A main function for testing */
017  public static void main (String[] args) {
018    for (double v : new double[] { 5, 7 }) {
019      testSumUntil (63, v, new double[] { 11, 21, 31, v, 41 });
020      testSumUntil (0, v, new double[] { v, 11, 21, 31, 41 });
021      testSumUntil (104, v, new double[] { 11, 21, 31, 41, v });
022      testSumUntil (11, v, new double[] { 11, v, 21, v, 31, 41 });
023      testSumUntil (0, v, new double[] { v });
024      testSumUntil (0, v, new double[] { v, v });
025      testSumUntil (104, v, new double[] { 11, 21, 31, 41 });
026      testSumUntil (11, v, new double[] { 11 });
027      testSumUntil (0, v, new double[] {});
028    }
029    StdOut.println ("Finished tests");
030  }
031  /* A main function for debugging -- change the name to "main" to run it */
032  public static void main2 (String[] args) {
033    //Trace.drawSteps ();
034    //Trace.drawStepsOfMethod ("sumUntil");
035    //Trace.drawStepsOfMethod ("sumUntilHelper");
036    //Trace.run ();
037    double[] list = new double[] { 11, 21, 31, 5, 41 };
038    double result = sumUntil (5, list);
039    StdOut.println ("result: " + result);
040  }
041}