2929import de .tilman_neumann .util .ConfigUtil ;
3030import de .tilman_neumann .util .SortedMultiset ;
3131
32+ import static de .tilman_neumann .jml .base .BigIntConstants .I_1 ;
33+
3234public class SquFoF63Test {
3335
3436 private static final Logger LOG = LogManager .getLogger (SquFoF63Test .class );
@@ -49,30 +51,41 @@ public void testSomeParticularNumbers() {
4951 }
5052
5153 /**
52- * Tests random composite numbers in the range where SquFoF63 should work correctly, i.e. up to 63 bit.
54+ * Tests smaller random composite numbers.
55+ */
56+ @ Test
57+ public void testSmallRandomComposites () {
58+ testRange (50 , 69 , 1000 );
59+ }
60+
61+ /**
62+ * Tests random composite numbers in the upper range where SquFoF63 works stable, i.e. up to 87 bit.
5363 */
5464 @ Test
55- public void testRandomComposites () {
56- int count = 10000 ;
57- for (int bits =50 ; bits <64 ; bits ++) { // 64 bit numbers are not completely safe
65+ public void testLargerRandomComposites () {
66+ testRange (70 , 86 , 100 );
67+ testRange (87 , 87 , 1000 );
68+ }
69+
70+ private void testRange (int minBits , int maxBits , int count ) {
71+ for (int bits =minBits ; bits <=maxBits ; bits ++) {
5872 BigInteger [] testNumbers = TestsetGenerator .generate (count , bits , TestNumberNature .RANDOM_ODD_COMPOSITES );
5973 LOG .info ("Testing " + count + " random numbers with " + bits + " bit..." );
6074 int failCount = 0 ;
6175 for (int i =0 ; i <count ; i ++) {
62- BigInteger NBig = testNumbers [i ];
63- long N = NBig .longValue ();
64- long squfofFactor = squfof63 .findSingleFactor (N );
65- if (squfofFactor < 2 ) {
66- long correctFactor = testFactorizer .findSingleFactor (NBig ).longValue ();
67- if (correctFactor > 1 && correctFactor <N ) {
76+ BigInteger N = testNumbers [i ];
77+ BigInteger squfofFactor = squfof63 .findSingleFactor (N );
78+ if (squfofFactor .compareTo (I_1 ) <= 0 ) {
79+ BigInteger correctFactor = testFactorizer .findSingleFactor (N );
80+ if (correctFactor .compareTo (I_1 )>0 && correctFactor .compareTo (N )<0 ) {
6881 LOG .debug ("N=" + N + ": SquFoF31 failed to find factor " + correctFactor );
6982 failCount ++;
7083 } else {
7184 LOG .error ("The reference factorizer failed to factor N=" + N + " !" );
7285 fail ();
7386 }
7487 } else {
75- if (N % squfofFactor != 0 ) {
88+ if (N . mod ( squfofFactor ). signum () != 0 ) {
7689 failCount ++;
7790 }
7891 }
0 commit comments