Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/io/zipcoder/Problem2.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package io.zipcoder;

public class Problem2 {

public String fibonacciIteration(int n) {
int nsub1 = 0;
int fibVal = 1;
StringBuilder output = new StringBuilder();
output.append(1);
while(fibVal + nsub1 < n) {
fibVal += nsub1;
output.append(", " + fibVal);
nsub1 = fibVal - nsub1;
}
return output.toString();
}

public String fibonacciRecursion(int n) {
return null;
}

}
33 changes: 33 additions & 0 deletions src/test/java/io/zipcoder/Problem2Test.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class Problem2Test {

Problem2 prob;

@Before
public void setup() {
prob = new Problem2();
}

@Test
public void fibonacciIteration() throws Exception {

int n = 20;

String expected = "1, 1, 2, 3, 5, 8, 13";
String actual = prob.fibonacciIteration(n);

Assert.assertEquals(expected, actual);
}

@Test
public void fibonacciRecursion() throws Exception {

int n = 25;

String expected = "1, 1, 2, 3, 5, 8, 13, 21";
String actual = prob.fibonacciIteration(n);

Assert.assertEquals(expected, actual);
}
}