@@ -10,21 +10,73 @@ class EulerPseudoprimeTest {
1010
1111 @ Test
1212 void testPrimeNumbers () {
13- assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (7 ), 10 ));
14- assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (13 ), 10 ));
15- assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (101 ), 10 ));
13+ assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (7 ), 5 ));
14+ assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (13 ), 5 ));
15+ assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (101 ), 5 ));
1616 }
1717
1818 @ Test
1919 void testCompositeNumbers () {
20- assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (9 ), 10 ));
21- assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (21 ), 10 ));
22- assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (221 ), 10 ));
20+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (9 ), 5 ));
21+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (21 ), 5 ));
22+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (221 ), 5 ));
2323 }
2424
2525 @ Test
2626 void testEvenNumbers () {
27- assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (4 ), 10 ));
28- assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (100 ), 10 ));
27+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (4 ), 5 ));
28+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (100 ), 5 ));
29+ }
30+
31+ @ Test
32+ void testEdgeCases () {
33+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (0 ), 5 ));
34+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (1 ), 5 ));
35+ assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (2 ), 5 ));
36+ assertTrue (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (3 ), 5 ));
37+ }
38+
39+ @ Test
40+ void testSingleTrialConsistency () {
41+ BigInteger n = BigInteger .valueOf (97 );
42+ boolean result1 = EulerPseudoprime .isProbablePrime (n , 1 );
43+ boolean result2 = EulerPseudoprime .isProbablePrime (n , 1 );
44+ assertEquals (result1 , result2 , "Results should be deterministic with constant seed" );
45+ }
46+
47+ @ Test
48+ void testJacobiSymbolBasicCases () throws Exception {
49+ var method = EulerPseudoprime .class .getDeclaredMethod ("jacobiSymbol" , BigInteger .class , BigInteger .class );
50+ method .setAccessible (true );
51+
52+ // (a/n) = (2/3) = -1
53+ assertEquals (-1 , (int ) method .invoke (null , BigInteger .valueOf (2 ), BigInteger .valueOf (3 )));
54+
55+ // (a/n) = (1/5) = 1
56+ assertEquals (1 , (int ) method .invoke (null , BigInteger .ONE , BigInteger .valueOf (5 )));
57+
58+ // (a/n) = (2/9) = 1
59+ assertEquals (1 , (int ) method .invoke (null , BigInteger .valueOf (2 ), BigInteger .valueOf (9 )));
60+
61+ // (a/n) = (3/9) = 0 since gcd(3,9)>1
62+ assertEquals (0 , (int ) method .invoke (null , BigInteger .valueOf (3 ), BigInteger .valueOf (9 )));
63+ }
64+
65+ @ Test
66+ void testUniformRandomRange () throws Exception {
67+ var method = EulerPseudoprime .class .getDeclaredMethod ("uniformRandom" , BigInteger .class , BigInteger .class );
68+ method .setAccessible (true );
69+
70+ BigInteger min = BigInteger .TWO ;
71+ BigInteger max = BigInteger .valueOf (20 );
72+ BigInteger value = (BigInteger ) method .invoke (null , min , max );
73+
74+ assertTrue (value .compareTo (min ) >= 0 && value .compareTo (max ) <= 0 , "Random value should be within [min, max]" );
75+ }
76+
77+ @ Test
78+ void testCompositeWithZeroJacobiSymbol () {
79+ // Choose n = 9, a = 3 → jacobi(3,9) = 0 should make it return false early
80+ assertFalse (EulerPseudoprime .isProbablePrime (BigInteger .valueOf (9 ), 1 ));
2981 }
3082}
0 commit comments