- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathFibonacciJavaStreamsTest.java
71 lines (58 loc) · 2.18 KB
/
FibonacciJavaStreamsTest.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
packagecom.thealgorithms.maths;
importjava.math.BigDecimal;
importjava.util.Optional;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
/**
* @author Albina Gimaletdinova on 25/07/2023
*/
publicclassFibonacciJavaStreamsTest {
privatestaticfinalStringEXCEPTION_MESSAGE = "Input index cannot be null or negative!";
@Test
publicvoidtestWithNegativeIndexShouldThrowException() {
Exceptionexception = Assertions.assertThrows(IllegalArgumentException.class, () -> FibonacciJavaStreams.calculate(newBigDecimal(-1)));
Assertions.assertEquals(EXCEPTION_MESSAGE, exception.getMessage());
}
@Test
publicvoidtestCheckTheFirst4SequenceElements() {
checkElement(BigDecimal.ZERO, BigDecimal.ZERO);
checkElement(BigDecimal.ONE, BigDecimal.ONE);
checkElement(BigDecimal.TWO, BigDecimal.ONE);
checkElement(newBigDecimal(3), BigDecimal.TWO);
}
@Test
publicvoidtestCheck10thSequenceElement() {
checkElement(BigDecimal.TEN, newBigDecimal(55));
}
@Test
publicvoidtestCheck20thSequenceElement() {
checkElement(newBigDecimal(20), newBigDecimal(6765));
}
@Test
publicvoidtestCheck30thSequenceElement() {
checkElement(newBigDecimal(30), newBigDecimal(832040));
}
@Test
publicvoidtestCheck40thSequenceElement() {
checkElement(newBigDecimal(40), newBigDecimal(102334155));
}
@Test
publicvoidtestCheck50thSequenceElement() {
checkElement(newBigDecimal(50), newBigDecimal(12586269025L));
}
@Test
publicvoidtestCheck100thSequenceElement() {
checkElement(newBigDecimal(100), newBigDecimal("354224848179261915075"));
}
@Test
publicvoidtestCheck200thSequenceElement() {
checkElement(newBigDecimal(200), newBigDecimal("280571172992510140037611932413038677189525"));
}
privatestaticvoidcheckElement(BigDecimalindex, BigDecimalexpected) {
// when
Optional<BigDecimal> result = FibonacciJavaStreams.calculate(index);
// then
Assertions.assertTrue(result.isPresent());
Assertions.assertEquals(result.get(), expected);
}
}