import org.junit.*; import static org.junit.Assert.*; /** * Test suite for a simple Fibonacci number calculator; requires * Junit 4.x. * * @author Wayne Eberly * */ public class FibTest2 { /* * The following method is not really necessary: * One could simply refer to "Fibonacci1.fib" instead * of "fib" in all the tests that appear below. * This is included as a courtesy in case you wish * to modify this test suite quickly, in order to * test other classes (like Fibonacci2) that also * provide a "fib" method */ private static long fib (int i ) { return Fibonacci1.fib(i); }; /* * Initial tests check that the method returns the * expected values at inputs 0-10 */ @Test public void testZero () { System.out.println("Testing evaluation at 0"); assertEquals(0, fib(0)); } @Test public void testOne () { System.out.println("Testing evaluation at 1"); assertEquals(1, fib(1)); } @Test public void testTwo () { System.out.println("Testing evaluation at 2"); assertEquals(1, fib(2)); } @Test public void testThree () { System.out.println("Testing evaluation at 3"); assertEquals(2, fib(3)); } @Test public void testFour () { System.out.println("Testing evaluation at 4"); assertEquals(3, fib(4)); } @Test public void testFive () { System.out.println("Testing evaluation at 5"); assertEquals(5, fib(5)); } @Test public void testSix () { System.out.println("Testing evaluation at 6"); assertEquals(8, fib(6)); } @Test public void testSeven () { System.out.println("Testing evaluation at 7"); assertEquals(13, fib(7)); } @Test public void testEight () { System.out.println("Testing evaluation at 8"); assertEquals(21, fib(8)); } @Test public void testNine () { System.out.println("Testing evaluation at 9"); assertEquals(34, fib(9)); } @Test public void testTen () { System.out.println("Testing evaluation at 10"); assertEquals(55, fib(10)); } /* * The final test checks whether the method throws * the expected exception when on input -1 */ @Test (expected = IllegalArgumentException.class) public void testNegative () { System.out.println("Testing evaluation at -1"); fib(-1); } }