Loading src/edu/bu/ec504/hw1p1/Main.java +15 −7 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.*; public class Main { // constants Loading @@ -20,22 +17,33 @@ public class Main { * ctual and reported numbers of distinct strings. */ static void test(ArrayList<String> testStrings, int MAX_DIFF) { Random rand = new Random(0); // fix the seed // Show the counter my test strings MyDistinctCounter tester = new MyDistinctCounter(memSize); Set<String> verifier = new HashSet<>(); // initially add ~1/2 of the strings for (String test: testStrings) { if (rand.nextBoolean()) { tester.saw(test); verifier.add(test); } } // Record the counter's state FixedBitArray savedState = tester.currentState(); // Output the guess // output current state and initialize a new counter MyDistinctCounter newTest = new MyDistinctCounter(memSize); newTest.setMem(savedState); // add all the strings to the new counter for (String test: testStrings) { tester.saw(test); verifier.add(test); } // Check that the answer is within accepted parameters int recorded = newTest.numDistinct(); int actual = verifier.size(); Loading Loading
src/edu/bu/ec504/hw1p1/Main.java +15 −7 Original line number Diff line number Diff line package edu.bu.ec504.hw1p1; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.*; public class Main { // constants Loading @@ -20,22 +17,33 @@ public class Main { * ctual and reported numbers of distinct strings. */ static void test(ArrayList<String> testStrings, int MAX_DIFF) { Random rand = new Random(0); // fix the seed // Show the counter my test strings MyDistinctCounter tester = new MyDistinctCounter(memSize); Set<String> verifier = new HashSet<>(); // initially add ~1/2 of the strings for (String test: testStrings) { if (rand.nextBoolean()) { tester.saw(test); verifier.add(test); } } // Record the counter's state FixedBitArray savedState = tester.currentState(); // Output the guess // output current state and initialize a new counter MyDistinctCounter newTest = new MyDistinctCounter(memSize); newTest.setMem(savedState); // add all the strings to the new counter for (String test: testStrings) { tester.saw(test); verifier.add(test); } // Check that the answer is within accepted parameters int recorded = newTest.numDistinct(); int actual = verifier.size(); Loading