diff --git a/src/edu/bu/ec504/hw1p1/Main.java b/src/edu/bu/ec504/hw1p1/Main.java index 67b3bfff0119a660a4ad5f9c8c0a278c73ca4775..d704dde7bbd3bf2a3c6d97613e4968407337220e 100644 --- a/src/edu/bu/ec504/hw1p1/Main.java +++ b/src/edu/bu/ec504/hw1p1/Main.java @@ -1,25 +1,47 @@ package edu.bu.ec504.hw1p1; +import com.sun.tools.javac.util.List; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; + public class Main { - /** - * Runs a simple test, based on the example in the homework description. - */ - static void simpleTest() { - String[] testStrings = {"Bravo", "Alfa", "Charlie", "Kilo", "Charlie", "Alfa", "Bravo"}; - myDistinctCounter foo = new myDistinctCounter(10); + static void test(ArrayList testStrings) { + // Show the counter my test strings + myDistinctCounter tester = new myDistinctCounter(10); for (String test: testStrings) { - foo.saw(test); + tester.saw(test); } - Byte[] savedState = foo.currentState(); + // Record the counter's state + Byte[] savedState = tester.currentState(); + System.out.println("Counter state is: "+ Arrays.toString(savedState)); + // Output the prediction myDistinctCounter newFoo = new myDistinctCounter(savedState); - System.out.println(newFoo.numDistinct()); + System.out.println("# of distinct strings: "+newFoo.numDistinct()); } public static void main(String[] args) { - simpleTest(); + + /** + * Runs a simple test, based on the example in the homework description. + */ + test(new ArrayList<>(List.of("Bravo", "Alfa", "Charlie", "Kilo", "Charlie", "Alfa", "Bravo"))); + + /** + * A more complicated test. + */ + final BigInteger two = new BigInteger("2"); + BigInteger base = two; + BigInteger modulus = new BigInteger("1911337"); // 10007 * 191 + ArrayList longList = new ArrayList<>(10000); + for (int ii=0; ii<10000; ii++) { + longList.add(base.toString()); + base=base.multiply(two).mod(modulus); + } + test(longList); } }