Skip to content

Commit 9bb80cf

Browse files
committed
use brute force as reference computation
1 parent 114a989 commit 9bb80cf

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/test/java/de/tilman_neumann/jml/quadraticResidues/QuadraticResiduesMod2PowNTest.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
import java.util.TreeSet;
2223

2324
import org.apache.logging.log4j.Logger;
2425
import org.junit.BeforeClass;
@@ -48,14 +49,27 @@ public class QuadraticResiduesMod2PowNTest {
4849
public static void setup() {
4950
ConfigUtil.initProject();
5051

51-
// reference computation
52+
// reference computation is brute force
5253
correctCounts = new ArrayList<Integer>();
5354
for (int n=0; n<NCOUNT; n++) {
54-
List<BigInteger> quadraticResidues = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_big(n);
55+
int m = 1<<n;
56+
TreeSet<Long> quadraticResidues = QuadraticResidues.getQuadraticResidues(m);
5557
LOG.info("n = " + n + " has " + quadraticResidues.size() + " quadratic residues modulo 2^" + n + (SHOW_ELEMENTS ? ": " + quadraticResidues : ""));
5658
correctCounts.add(quadraticResidues.size());
5759
}
58-
LOG.info("v0 counts = " + correctCounts);
60+
LOG.info("correctCounts = " + correctCounts);
61+
}
62+
63+
@Test
64+
public void testV0() {
65+
ArrayList<Integer> counts = new ArrayList<Integer>();
66+
for (int n=0; n<NCOUNT; n++) {
67+
List<BigInteger> quadraticResidues = QuadraticResiduesMod2PowN.getQuadraticResiduesMod2PowN_testAll_big(n);
68+
if (DEBUG) LOG.debug("v0: n = " + n + " has " + quadraticResidues.size() + " quadratic residues modulo 2^" + n + (SHOW_ELEMENTS ? ": " + quadraticResidues : ""));
69+
counts.add(quadraticResidues.size());
70+
}
71+
LOG.info("v0 counts = " + counts);
72+
assertEquals(correctCounts, counts);
5973
}
6074

6175
@Test

0 commit comments

Comments
 (0)