forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShorAlgorithmTest.java
49 lines (37 loc) · 1.7 KB
/
ShorAlgorithmTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.thealgorithms.others;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.math.BigInteger;
import org.junit.jupiter.api.Test;
public class ShorAlgorithmTest {
@Test
public void testFactorizationOfEvenNumber() {
ShorAlgorithm shor = new ShorAlgorithm();
BigInteger number = new BigInteger("15");
BigInteger[] factors = shor.shorAlgorithm(number);
assertNotNull(factors, "Factors should not be null for composite numbers.");
assertEquals(2, factors.length, "There should be two factors.");
BigInteger p = factors[0];
BigInteger q = factors[1];
assertEquals(number, p.multiply(q), "Factors should multiply to the original number.");
}
@Test
public void testFactorizationOfPrimeNumber() {
ShorAlgorithm shor = new ShorAlgorithm();
BigInteger number = new BigInteger("13");
BigInteger[] factors = shor.shorAlgorithm(number);
assertNull(factors, "Factors should be null for prime numbers.");
}
@Test
public void testFactorizationOfEvenCompositeNumber() {
ShorAlgorithm shor = new ShorAlgorithm();
BigInteger number = new BigInteger("20");
BigInteger[] factors = shor.shorAlgorithm(number);
assertNotNull(factors, "Factors should not be null for composite numbers.");
assertEquals(2, factors.length, "There should be two factors.");
BigInteger p = factors[0];
BigInteger q = factors[1];
assertEquals(number, p.multiply(q), "Factors should multiply to the original number.");
}
}