Skip to content

Commit f35eef2

Browse files
authored
Add tests for GCD and PrimeCheck (TheAlgorithms#3062)
1 parent 550adb2 commit f35eef2

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.thealgorithms.maths;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class GCDTest {
7+
@Test
8+
void test1() {
9+
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-1,0));
10+
}
11+
12+
@Test
13+
void test2() {
14+
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(10, -2));
15+
}
16+
17+
@Test
18+
void test3() {
19+
Assertions.assertThrows(ArithmeticException.class, () -> GCD.gcd(-5, -3));
20+
}
21+
22+
@Test
23+
void test4() {
24+
Assertions.assertEquals(GCD.gcd(0, 2), 2);
25+
}
26+
27+
@Test
28+
void test5() {
29+
Assertions.assertEquals(GCD.gcd(10, 0), 10);
30+
}
31+
32+
@Test
33+
void test6() {
34+
Assertions.assertEquals(GCD.gcd(1, 0), 1);
35+
}
36+
37+
@Test
38+
void test7() {
39+
Assertions.assertEquals(GCD.gcd(9, 6), 3);
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.thealgorithms.maths;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class PrimeCheckTest {
7+
@Test
8+
void test1() {
9+
Assertions.assertTrue(PrimeCheck.isPrime(2));
10+
}
11+
12+
@Test
13+
void test2() {
14+
Assertions.assertFalse(PrimeCheck.isPrime(-1));
15+
}
16+
17+
@Test
18+
void test3() {
19+
Assertions.assertFalse(PrimeCheck.isPrime(4));
20+
}
21+
22+
@Test
23+
void test4() {
24+
Assertions.assertTrue(PrimeCheck.isPrime(5));
25+
}
26+
27+
@Test
28+
void test5() {
29+
Assertions.assertFalse(PrimeCheck.isPrime(15));
30+
}
31+
32+
@Test
33+
void test6() {
34+
Assertions.assertTrue(PrimeCheck.isPrime(11));
35+
}
36+
37+
@Test
38+
void test7() {
39+
Assertions.assertFalse(PrimeCheck.isPrime(49));
40+
}
41+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy