17
17
import static org .junit .Assert .fail ;
18
18
19
19
import java .math .BigInteger ;
20
+ import java .util .List ;
20
21
21
22
import org .apache .logging .log4j .LogManager ;
22
23
import org .apache .logging .log4j .Logger ;
23
24
import org .junit .BeforeClass ;
24
25
import org .junit .Test ;
25
26
26
27
import de .tilman_neumann .jml .factor .FactorAlgorithm ;
28
+ import de .tilman_neumann .jml .factor .FactorTestInfrastructure ;
27
29
import de .tilman_neumann .jml .factor .TestNumberNature ;
28
30
import de .tilman_neumann .jml .factor .TestsetGenerator ;
29
31
import de .tilman_neumann .util .ConfigUtil ;
@@ -35,14 +37,18 @@ public class SquFoF63Test {
35
37
36
38
private static final Logger LOG = LogManager .getLogger (SquFoF63Test .class );
37
39
38
- private static SquFoF63 squfof63 ;
39
- private static FactorAlgorithm testFactorizer ;
40
+ private static final SquFoF63 squfof = new SquFoF63 () ;
41
+ private static final FactorAlgorithm verificationFactorizer = FactorAlgorithm . getDefault () ;
40
42
41
43
@ BeforeClass
42
44
public static void setup () {
43
45
ConfigUtil .initProject ();
44
- squfof63 = new SquFoF63 ();
45
- testFactorizer = FactorAlgorithm .getDefault ();
46
+ }
47
+
48
+ @ Test
49
+ public void testSmallestComposites () {
50
+ List <Integer > fails = FactorTestInfrastructure .testSmallComposites (100000 , squfof );
51
+ assertEquals ("Failed to factor n = " + fails , 0 , fails .size ());
46
52
}
47
53
48
54
@ Test
@@ -74,9 +80,9 @@ private void testRange(int minBits, int maxBits, int count) {
74
80
int failCount = 0 ;
75
81
for (int i =0 ; i <count ; i ++) {
76
82
BigInteger N = testNumbers [i ];
77
- BigInteger squfofFactor = squfof63 .findSingleFactor (N );
83
+ BigInteger squfofFactor = squfof .findSingleFactor (N );
78
84
if (squfofFactor .compareTo (I_1 ) <= 0 ) {
79
- BigInteger correctFactor = testFactorizer .findSingleFactor (N );
85
+ BigInteger correctFactor = verificationFactorizer .findSingleFactor (N );
80
86
if (correctFactor .compareTo (I_1 )>0 && correctFactor .compareTo (N )<0 ) {
81
87
LOG .debug ("N=" + N + ": SquFoF63 failed to find factor " + correctFactor );
82
88
failCount ++;
@@ -98,7 +104,7 @@ private void testRange(int minBits, int maxBits, int count) {
98
104
private void assertFactorizationSuccess (long N , String expectedPrimeFactorizationStr ) {
99
105
BigInteger NBig = BigInteger .valueOf (N );
100
106
LOG .info ("Test " + N + " (" + NBig .bitLength () + " bit)" );
101
- SortedMultiset <BigInteger > factors = squfof63 .factor (NBig );
107
+ SortedMultiset <BigInteger > factors = squfof .factor (NBig );
102
108
LOG .info (N + " = " + factors .toString ("*" , "^" ));
103
109
assertEquals (expectedPrimeFactorizationStr , factors .toString ("*" , "^" ));
104
110
}
0 commit comments