Potrzebuję pomocy z testem parametryzowanym. Nie rozumiem dlaczego pojawiają mi się te błędy przy takim kodzie:
@RunWith(Parameterized.class)
public static class FibonacciTest {
@Parameters(name = "{index}: fib({0})={1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
{ 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 }
});
}
private int input;
private int expected;
public FibonacciTest(int input, int expected) {
this.input = input;
this.expected = expected;
}
@Test
public void test() {
Assertions.assertEquals(expected, Fibonacci.compute(input));
}
}
public static class Fibonacci {
public static int compute(int index){
if (index == 0) return 0;
if (index == 1) return 1;
int prevPrev = 0;
int prev = 1;
int result = 0;
for (int i = 2; i <= index; i++)
{
result = prev + prevPrev;
prevPrev = prev;
prev = result;
}
return result;
}
}
Screen z IDE:
https://imgur.com/nev0MIE