Skip to content

Commit 8203d7a

Browse files
committed
test all four kinds of test numbers
1 parent 1ce1305 commit 8203d7a

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

src/test/java/de/tilman_neumann/jml/factor/TestsetGeneratorTest.java

+47-19
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
package de.tilman_neumann.jml.factor;
1515

1616
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertTrue;
1718

1819
import java.math.BigInteger;
19-
import java.util.Map;
20-
import java.util.TreeMap;
2120

2221
import org.apache.logging.log4j.Logger;
2322
import org.junit.BeforeClass;
@@ -35,36 +34,65 @@ public class TestsetGeneratorTest {
3534
private static final int NCOUNT = 10;
3635
private static final int MIN_BITS = 20;
3736
private static final int MAX_BITS = 1000;
38-
private static final int INCR_BITS = 10;
37+
private static final int INCR_BITS = 20;
3938

4039
@BeforeClass
4140
public static void setup() {
4241
ConfigUtil.initProject();
4342
}
4443

4544
@Test
46-
public void testGeneratedNumberSize() {
45+
public void testRandomComposites() {
46+
Timer timer = new Timer();
47+
for (int bits = MIN_BITS; bits<=MAX_BITS; bits+=INCR_BITS) {
48+
BigInteger[] testNumbers = TestsetGenerator.generate(NCOUNT, bits, TestNumberNature.RANDOM_COMPOSITES);
49+
for (BigInteger num : testNumbers) {
50+
assertEquals(bits, num.bitLength());
51+
assertTrue(num.signum() > 0);
52+
}
53+
}
54+
LOG.info("Computing random composites took " + TimeUtil.timeStr(timer.totalRuntime()));
55+
}
56+
57+
@Test
58+
public void testRandomOddComposites() {
59+
Timer timer = new Timer();
60+
for (int bits = MIN_BITS; bits<=MAX_BITS; bits+=INCR_BITS) {
61+
BigInteger[] testNumbers = TestsetGenerator.generate(NCOUNT, bits, TestNumberNature.RANDOM_ODD_COMPOSITES);
62+
for (BigInteger num : testNumbers) {
63+
assertEquals(bits, num.bitLength());
64+
assertTrue(num.signum() > 0);
65+
assertEquals(num.intValue() & 1, 1);
66+
}
67+
}
68+
LOG.info("Computing random odd composites took " + TimeUtil.timeStr(timer.totalRuntime()));
69+
}
70+
71+
@Test
72+
public void testModerateSemiprimes() {
4773
Timer timer = new Timer();
4874
for (int bits = MIN_BITS; bits<=MAX_BITS; bits+=INCR_BITS) {
49-
long start = timer.capture();
5075
BigInteger[] testNumbers = TestsetGenerator.generate(NCOUNT, bits, TestNumberNature.MODERATE_SEMIPRIMES);
51-
long end = timer.capture();
52-
// Collect the true bit lengths
53-
Map<Integer, Integer> sizeCounts = new TreeMap<>();
5476
for (BigInteger num : testNumbers) {
55-
int bitlen = num.bitLength();
56-
Integer count = sizeCounts.get(bitlen);
57-
count = (count==null) ? Integer.valueOf(1) : count.intValue()+1;
58-
sizeCounts.put(bitlen, count);
77+
assertEquals(bits, num.bitLength());
78+
assertTrue(num.signum() > 0);
79+
// we dont want to factor the numbers here to prove they are semiprimes
5980
}
60-
String generatedBitLengths = "";
61-
for (int bitlen : sizeCounts.keySet()) {
62-
generatedBitLengths += sizeCounts.get(bitlen) + "x" + bitlen + ", ";
81+
}
82+
LOG.info("Computing moderate semiprimes took " + TimeUtil.timeStr(timer.totalRuntime()));
83+
}
84+
85+
@Test
86+
public void testHardSemiprimes() {
87+
Timer timer = new Timer();
88+
for (int bits = MIN_BITS; bits<=MAX_BITS; bits+=INCR_BITS) {
89+
BigInteger[] testNumbers = TestsetGenerator.generate(NCOUNT, bits, TestNumberNature.QUITE_HARD_SEMIPRIMES);
90+
for (BigInteger num : testNumbers) {
91+
assertEquals(bits, num.bitLength());
92+
assertTrue(num.signum() > 0);
93+
// we dont want to factor the numbers here to prove they are semiprimes
6394
}
64-
generatedBitLengths = generatedBitLengths.substring(0, generatedBitLengths.length()-2);
65-
LOG.info("Requesting " + NCOUNT + " " + bits + "-numbers took " + TimeUtil.timeDiffStr(start, end) + " ms and generated the following bit lengths: " + generatedBitLengths);
66-
// all generated test numbers have the requested bit length
67-
assertEquals(NCOUNT + "x" + bits, generatedBitLengths);
6895
}
96+
LOG.info("Computing quite hard semiprimes took " + TimeUtil.timeStr(timer.totalRuntime()));
6997
}
7098
}

0 commit comments

Comments
 (0)