001package algs11;
002import java.util.Arrays;
003import stdlib.*;
004public class PlaygroundLongestSequenceOf5s {
005        /* Return the length of the longest contiguous sequence of 5.0s in the list */
006        public static int longestSequenceOf5s (double[] list) {
007                return StdRandom.uniform (100); //TODO: fix this
008        }
009        /* This is a test function */
010        public static void testLongestSequence (int expected, double[] list) {
011                int actual = longestSequenceOf5s (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                testLongestSequence (3, new double[] { 1, 5, 5, 1, 1, 5, 5, 5, 1, 5, 5, 1});
019                testLongestSequence (4, new double[] { 1, 5, 1, 5, 5, 5, 5, 1, 5});
020                testLongestSequence (2, new double[] { 5, 5, 1, 1, 5, 5, 1, 5, 5});
021                testLongestSequence (4, new double[] { 1, 5, 1, 5, 5, 5, 5, 1, 5, 1});
022                testLongestSequence (3, new double[] { 1, 5, 5, 5, 1, 5, 1});
023                testLongestSequence (0, new double[] { 1 });
024                testLongestSequence (1, new double[] { 5 });
025                testLongestSequence (3, new double[] { 5, 5, 5 });
026                testLongestSequence (0, new double[] { });
027                StdOut.println ("Finished tests");
028        }
029        /* A main function for debugging -- change the name to "main" to run it */
030        public static void main2 (String[] args) {
031                //Trace.drawSteps ();
032                Trace.drawStepsOfMethod ("longestSequenceOf5s");
033                Trace.drawStepsOfMethod ("longestSequenceOf5sHelper");
034                Trace.run ();
035                double[] list = new double[] { 5, 11, 5, 5 };
036                double result = longestSequenceOf5s (list);
037                StdOut.println ("result: " + result);
038        }
039}