-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcom.joshuadargan.TestPrimes.java
142 lines (130 loc) · 4.05 KB
/
com.joshuadargan.TestPrimes.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.math.BigInteger;
class TestPrimes
{
public static void main(String[] args)
{
boolean allPass = true;
allPass = allPass && TestNegativeNumber();
allPass = allPass && TestZero();
allPass = allPass && TestFirstPrime();
allPass = allPass && TestSecondPrime();
allPass = allPass && TestThirdPrime();
allPass = allPass && Test100thPrime();
allPass = allPass && TestMillonthPrime();
allPass = allPass && TestMillonthPrime();
allPass = allPass && TestReleaseMemory();
allPass = allPass && TestBillonthPrime();
allPass = allPass && TestMillonthPrime();
allPass = allPass && Test100thPrime();
allPass = allPass && TestThirdPrime();
allPass = allPass && TestSecondPrime();
allPass = allPass && TestFirstPrime();
if (allPass)
System.out.println("All tests were successful");
}
public static boolean TestNegativeNumber()
{
//If it returns a zero
if (Primes.FindNthPrime(-1).compareTo(BigInteger.ZERO) == 0)
{
System.out.println("TestNegativeNumbers successful");
return true;
}
else
System.out.println("TestNegativeNumber failed");
return false;
}
public static boolean TestZero()
{
//If it returns a zero
if (Primes.FindNthPrime(0).compareTo(BigInteger.ZERO) == 0)
{
System.out.println("TestZero successful");
return true;
}
else
System.out.println("TestZero failed");
return false;
}
public static boolean TestFirstPrime()
{
if (Primes.FindNthPrime(1).compareTo(BigInteger.TWO) == 0)
{
System.out.println("TestFirstPrime successful");
return true;
}
else
System.out.println("TestFirstPrime failed");
return false;
}
public static boolean TestSecondPrime()
{
if (Primes.FindNthPrime(2).compareTo(BigInteger.valueOf(3)) == 0)
{
System.out.println("TestSecondPrime successful");
return true;
}
else
System.out.println("TestSecondPrime failed");
return false;
}
public static boolean TestThirdPrime()
{
if (Primes.FindNthPrime(3).compareTo(BigInteger.valueOf(5)) == 0)
{
System.out.println("TestThirdPrime successful");
return true;
}
else
System.out.println("TestThirdPrime failed");
return false;
}
public static boolean Test100thPrime()
{
BigInteger prime100th = BigInteger.valueOf(541);
if (Primes.FindNthPrime(100).compareTo(prime100th) == 0)
{
System.out.println("Test100thPrime successful");
return true;
}
else
System.out.println("Test100thPrime failed");
return false;
}
public static boolean TestMillonthPrime()
{
BigInteger primeMillionth = new BigInteger("15485863");
if (Primes.FindNthPrime(1000000).compareTo(primeMillionth) == 0)
{
System.out.println("TestMillionthPrime successful");
return true;
}
else
System.out.println("TestMillionthPrime failed");
return false;
}
public static boolean TestBillonthPrime()
{
BigInteger primeMillionth = new BigInteger("22801763489");
if (Primes.FindNthPrime(1000000000).compareTo(primeMillionth) == 0)
{
System.out.println("TestBillionthPrime successful");
return true;
}
else
System.out.println("TestBillionthPrime failed");
return false;
}
public static boolean TestReleaseMemory()
{
Primes.ReleaseMemory();
if (Primes.GetPrimeList().size() == 0)
{
System.out.println("TestReleaseMemory successful");
return true;
}
else
System.out.println("TestReleaseMemory failed");
return false;
}
}