forked from RasPat1/practice-codewars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FibonacciTest.java
126 lines (105 loc) · 2.49 KB
/
FibonacciTest.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
import java.math.BigInteger;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class FibonacciTest {
@Test
public void testFib0() {
testFib(0, 0);
}
@Test
public void testFib1() {
testFib(1, 1);
}
@Test
public void testFib2() {
testFib(1, 2);
}
@Test
public void testFib3() {
testFib(2, 3);
}
@Test
public void testFib4() {
testFib(3, 4);
}
@Test
public void testFib5() {
testFib(5, 5);
}
@Test
public void testFib6() {
testFib(8, 6);
}
@Test
public void testFib7() {
testFib(13, 7);
}
@Test
public void testFib8() {
testFib(21, 8);
}
@Test
public void testFib9() {
testFib(34, 9);
}
/******************************************************************************
Negative
******************************************************************************/
// @Test
// public void testFibNeg1() {
// testFib(1, -1);
// }
// @Test
// public void testFibNeg2() {
// testFib(-1, -2);
// }
// @Test
// public void testFibNeg3() {
// testFib(2, -3);
// }
// @Test
// public void testFibNeg4() {
// testFib(-3, -4);
// }
// @Test
// public void testFibNeg5() {
// testFib(5, -5);
// }
// @Test
// public void testFibNeg6() {
// testFib(-8, -6);
// }
/******************************************************************************
Really Big
******************************************************************************/
// @Test
// public void testFibLarge() {
// testFib("359579325206583560961765665172189099052367214309267232255589801", 301);
// }
// @Test
// public void testFibSoBig() {
// testFib("359579325206583560961765665172189099052367214309267232255589801", 1000000);
// }
private static void testFib(String expected, long input) {
BigInteger found;
try {
found = Fibonacci.fib(BigInteger.valueOf(input));
}
catch (Throwable e) {
// see https://github.com/Codewars/codewars.com/issues/21
throw new AssertionError("exception during test: "+e, e);
}
assertEquals(new BigInteger(expected), found);
}
private static void testFib(long expected, long input) {
BigInteger found;
try {
found = Fibonacci.fib(BigInteger.valueOf(input));
}
catch (Throwable e) {
// see https://github.com/Codewars/codewars.com/issues/21
throw new AssertionError("exception during test: "+e, e);
}
assertEquals(BigInteger.valueOf(expected), found);
}
}