|
19 | 19 | import java.util.ArrayList;
|
20 | 20 | import java.util.Arrays;
|
21 | 21 | import java.util.List;
|
| 22 | +import java.util.TreeSet; |
22 | 23 |
|
23 | 24 | import org.apache.logging.log4j.Logger;
|
24 | 25 | import org.junit.BeforeClass;
|
@@ -48,14 +49,27 @@ public class QuadraticResiduesMod2PowNTest {
|
48 | 49 | public static void setup() {
|
49 | 50 | ConfigUtil.initProject();
|
50 | 51 |
|
51 |
| - // reference computation |
| 52 | + // reference computation is brute force |
52 | 53 | correctCounts = new ArrayList<Integer>();
|
53 | 54 | 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); |
55 | 57 | LOG.info("n = " + n + " has " + quadraticResidues.size() + " quadratic residues modulo 2^" + n + (SHOW_ELEMENTS ? ": " + quadraticResidues : ""));
|
56 | 58 | correctCounts.add(quadraticResidues.size());
|
57 | 59 | }
|
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); |
59 | 73 | }
|
60 | 74 |
|
61 | 75 | @Test
|
|
0 commit comments