Browse Source

Add project

master
Simon Larsén 3 years ago
commit
d9427aef7b
3 changed files with 68 additions and 0 deletions
  1. +16
    -0
      README.md
  2. +19
    -0
      src/Fibo.java
  3. +33
    -0
      src/FiboTest.java

+ 16
- 0
README.md View File

@ -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.

+ 19
- 0
src/Fibo.java View File

@ -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;
}
}

+ 33
- 0
src/FiboTest.java View File

@ -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));
}
}

Loading…
Cancel
Save