-
Notifications
You must be signed in to change notification settings - Fork 19.7k
/
Copy pathCollatzConjectureTest.java
41 lines (32 loc) · 1.16 KB
/
CollatzConjectureTest.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
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
class CollatzConjectureTest {
static CollatzConjecture cConjecture;
@BeforeAll
static void setUp() {
cConjecture = new CollatzConjecture();
}
@Test
void nextNumberFromEvenNumber() {
assertEquals(25, cConjecture.nextNumber(50));
}
@Test
void nextNumberFromOddNumber() {
assertEquals(154, cConjecture.nextNumber(51));
}
@Test
void collatzConjecture() {
final List<Integer> expected = List.of(35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1);
assertIterableEquals(expected, cConjecture.collatzConjecture(35));
}
@Test
void sequenceOfNotNaturalFirstNumber() {
assertThrows(IllegalArgumentException.class, () -> cConjecture.collatzConjecture(0));
assertThrows(IllegalArgumentException.class, () -> cConjecture.collatzConjecture(-1));
}
}