From d9427aef7b6120b9371620baea32ea1adbc23d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Lars=C3=A9n?= Date: Sat, 6 Mar 2021 21:27:04 +0000 Subject: [PATCH] Add project --- README.md | 16 ++++++++++++++++ src/Fibo.java | 19 +++++++++++++++++++ src/FiboTest.java | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 README.md create mode 100644 src/Fibo.java create mode 100644 src/FiboTest.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe78609 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# RepoBee demo task-2 + +Welcome to the instructions for task-2! Complete the exercises listed below and +submit the results by pushing them to your repository. + +### Exercise 1 + +Run the tests in `FiboTest.java` with `JUnit4` and ensure that they both fail. +Then add another test that tests that the thousandth number is correctly +generated, run the tests again, and ensure that they all still fail. + +### Exercise 2 + +Implement the `next()` method in `Fibo.java` such that it returns Fibonacci +numbers in the correct sequence. Make sure that the tests pass, including the +one you added in the previous exercise. diff --git a/src/Fibo.java b/src/Fibo.java new file mode 100644 index 0000000..8b776da --- /dev/null +++ b/src/Fibo.java @@ -0,0 +1,19 @@ +/** + * Class for calculating Fibonacci numbers. + */ +public class Fibo { + private long prev; + private long current; + + public Fibo() { + prev = 0; + current = 1; + } + + /** + * Generate the next Fibonacci number. + */ + public long next() { + return 0; + } +} diff --git a/src/FiboTest.java b/src/FiboTest.java new file mode 100644 index 0000000..deba6ac --- /dev/null +++ b/src/FiboTest.java @@ -0,0 +1,33 @@ +import org.junit.Test; +import org.junit.Before; +import static org.junit.Assert.*; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.*; + +public class FiboTest { + @Test + public void correctlyGeneratesFirst10Numbers() { + Fibo f = new Fibo(); + long[] expected = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}; + long[] actual = new long[10]; + + for (int i = 0; i < 10; i++) { + actual[i] = f.next(); + } + + assertThat(actual, equalTo(expected)); + } + + @Test + public void correctlyGeneratesFiftiethNumber() { + // note that the first number is counted as the 0th + Fibo f = new Fibo(); + + for (int i = 0; i < 50; i++) { + f.next(); + } + + assertThat(f.next(), equalTo(12586269025l)); + } +}