CSC300: Starter code [1/12] Previous pageContentsNext page

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package algs11;
import java.util.Arrays;
import stdlib.*;
public class Playground {
  /* Return number of times 5.0 occurs in the list */
  public static int numFives (double[] list) {
    return StdRandom.uniform (100); //TODO: fix this
  }
  /* This is a test function */
  public static void testNumFives (int expected, double[] list) {
    int actual = numFives (list);
    if (expected != actual) {
      StdOut.format ("Failed: Expecting [%d] Actual [%d] with argument %s\n", expected, actual, Arrays.toString (list));
    }
  }
  /* A main function for testing */
  public static void main (String[] args) {
    testNumFives (3, new double[] { 11, 21, 5, 31, 5, 41, 5, 51});
    testNumFives (4, new double[] { 11, 21, 5, 31, 5, 5, 41, 5, 51});
    testNumFives (4, new double[] { 11, 21, 5, 5, 5, 31, 41, 5, 51});
    testNumFives (0, new double[] { 11, 21, 31, 41 });
    testNumFives (1, new double[] { 11, 21, 5, 31, 41 });
    testNumFives (1, new double[] { 11, 21, 31, 41, 5 });
    testNumFives (1, new double[] { 5, 11, 21, 31, 41 });
    testNumFives (0, new double[] { 11 });
    testNumFives (1, new double[] { 5 });
    testNumFives (3, new double[] { 5, 5, 5 });
    testNumFives (0, new double[] { });
    StdOut.println ("Finished tests");
  }
}

Previous pageContentsNext page