Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c483e99

Browse files
committedAug 4, 2017
import version 6.1.2
1 parent ec2b72c commit c483e99

File tree

143 files changed

+2747
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+2747
-0
lines changed
 

‎ap01/Series.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Example method from Chapter 6.
3+
*/
4+
public class Series {
5+
6+
public static int fibonacci(int n) {
7+
if (n == 1 || n == 2) {
8+
return 1;
9+
}
10+
return fibonacci(n - 1) + fibonacci(n - 2);
11+
}
12+
13+
public static void main(String[] args) {
14+
if (fibonacci(1) != 1) {
15+
System.err.println("fibonacci(1) is incorrect");
16+
}
17+
if (fibonacci(2) != 1) {
18+
System.err.println("fibonacci(2) is incorrect");
19+
}
20+
if (fibonacci(3) != 2) {
21+
System.err.println("fibonacci(3) is incorrect");
22+
}
23+
}
24+
25+
}

‎ap01/SeriesTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import junit.framework.TestCase;
2+
3+
/**
4+
* Example JUnit test from Appendix A.
5+
*/
6+
public class SeriesTest extends TestCase {
7+
8+
public void testFibonacci() {
9+
assertEquals(1, Series.fibonacci(1));
10+
assertEquals(1, Series.fibonacci(2));
11+
assertEquals(2, Series.fibonacci(3));
12+
}
13+
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.