forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFibonacciLoopTest.java
More file actions
36 lines (29 loc) · 984 Bytes
/
FibonacciLoopTest.java
File metadata and controls
36 lines (29 loc) · 984 Bytes
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
package com.thealgorithms.maths;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigInteger;
import org.junit.jupiter.api.Test;
public class FibonacciLoopTest {
@Test
public void checkValueAtZero() {
assertEquals(BigInteger.ZERO, FibonacciLoop.compute(0));
}
@Test
public void checkValueAtOne() {
assertEquals(BigInteger.ONE, FibonacciLoop.compute(1));
}
@Test
public void checkValueAtTwo() {
assertEquals(BigInteger.ONE, FibonacciLoop.compute(2));
}
@Test
public void checkRecurrenceRelation() {
for (int i = 0; i < 100; ++i) {
assertEquals(FibonacciLoop.compute(i + 2), FibonacciLoop.compute(i + 1).add(FibonacciLoop.compute(i)));
}
}
@Test
public void checkNegativeInput() {
assertThrows(IllegalArgumentException.class, () -> { FibonacciLoop.compute(-1); });
}
}