From 64a1db73a309029ed66e9707b3222750649b879c Mon Sep 17 00:00:00 2001 From: logan Date: Mon, 27 Nov 2017 11:17:34 -0500 Subject: [PATCH] meh --- src/main/java/io/zipcoder/Problem2.java | 18 +++++++++++ src/test/java/io/zipcoder/Problem2Test.java | 33 +++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/main/java/io/zipcoder/Problem2.java b/src/main/java/io/zipcoder/Problem2.java index e0af6a0..0ed2d0b 100644 --- a/src/main/java/io/zipcoder/Problem2.java +++ b/src/main/java/io/zipcoder/Problem2.java @@ -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; + } + } diff --git a/src/test/java/io/zipcoder/Problem2Test.java b/src/test/java/io/zipcoder/Problem2Test.java index fa9ffa5..a3d21a3 100644 --- a/src/test/java/io/zipcoder/Problem2Test.java +++ b/src/test/java/io/zipcoder/Problem2Test.java @@ -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); + } }