Commit 3a78d8d1 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

some tests

parent e783275e
Loading
Loading
Loading
Loading
+32 −10
Original line number Diff line number Diff line
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<String> 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<String> longList = new ArrayList<>(10000);
        for (int ii=0; ii<10000; ii++) {
            longList.add(base.toString());
            base=base.multiply(two).mod(modulus);
        }
        test(longList);
    }
}