Skip to content
Open

hi #17

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
29 changes: 29 additions & 0 deletions src/main/java/io/zipcoder/Problem2.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
package io.zipcoder;

public class Problem2 {

public String fibonnaciToN(Integer n) {

String output = "0, 1, ";
int x = 0, y = 1, z = 1;
for (int i = 0; z < n-1; i++) {
x = y;
y = z;
output += z +", ";
z = x + y;


}
return output.substring(0, output.length()-2);
}


public String fibonnaciToNRecursive(Integer n) {

Integer i = 1;

while(i<n) {
fibonnaciToNRecursive(i + 1);

}

return i;
}
}

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

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

public class Problem2Test {

@Test
public void testFibonacciIterative(){

Problem2 problem2 = new Problem2();

Integer n = 150;
String expected = "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144";
String actual = problem2.fibonnaciToN(150);

Assert.assertEquals(expected,actual);
}

@Test
public void testFibonacciRecursive(){

Problem2 problem2 = new Problem2();

Integer n = 150;
String expected = "0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144";
String actual = problem2.fibonnaciToNRecursive(150);

Assert.assertEquals(expected,actual);
}
}