001package algs11;
002import java.util.Arrays;
003import stdlib.*;
004public class Playground {
005        /* Return number of times 5.0 occurs in the list */
006        public static int numFives (double[] a) {
007                return StdRandom.uniform (100); //TODO: fix this
008        }
009        /* This is a test function */
010        public static void testNumFives (int expected, double[] list) {
011                int actual = numFives (list);
012                if (expected != actual) {
013                        StdOut.format ("Failed: Expecting [%d] Actual [%d] with argument %s\n", expected, actual, Arrays.toString (list));
014                }
015        }
016        /* A main function for testing */
017        public static void main (String[] args) {
018                testNumFives (3, new double[] { 11, 21, 5, 31, 5, 41, 5, 51});
019                testNumFives (4, new double[] { 11, 21, 5, 31, 5, 5, 41, 5, 51});
020                testNumFives (4, new double[] { 11, 21, 5, 5, 5, 31, 41, 5, 51});
021                testNumFives (0, new double[] { 11, 21, 31, 41 });
022                testNumFives (1, new double[] { 11, 21, 5, 31, 41 });
023                testNumFives (1, new double[] { 11, 21, 31, 41, 5 });
024                testNumFives (1, new double[] { 5, 11, 21, 31, 41 });
025                testNumFives (0, new double[] { 11 });
026                testNumFives (1, new double[] { 5 });
027                testNumFives (3, new double[] { 5, 5, 5 });
028                testNumFives (0, new double[] { });
029                StdOut.println ("Finished tests");
030        }
031        /* A main function for debugging -- change the name to "main" to run it */
032        public static void main1 (String[] args) {
033                //Trace.drawSteps ();
034                Trace.drawStepsOfMethod ("numFives");
035                Trace.drawStepsOfMethod ("numFivesHelper");
036                Trace.run ();
037                double[] list = new double[] { 5, 11, 5, 5 };
038                double result = numFives (list);
039                StdOut.println ("result: " + result);
040        }
041}