Created
December 27, 2014 16:18
-
-
Save kevinrutherford/bf4c2057d0223f5c0f2c to your computer and use it in GitHub Desktop.
Revisions
-
kevinrutherford created this gist
Dec 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class OsheroveTests { private Calculator calculator; @Before public void setUp() throws Exception { StringFormat format = new MultiCharDelimiter( new SelfDescribingList( new VanillaNumbersList())); NumberValidator[] numberRules = { new PreventNegatives(), new IgnoreThousands() }; this.calculator = new Calculator(format, new NonZeroFunction( new ArraySum(new NumberParser(numberRules)))); } @Test public void addsNumbers() { assertEquals(0, calculator.add("")); assertEquals(1, calculator.add("1")); assertEquals(3, calculator.add("1,2")); } @Test public void addsManyNumbers() { assertEquals(290, calculator.add("1,2,34,56,7,89,101")); } @Test public void allowsNewlineAsSeparator() { assertEquals(12, calculator.add("3\n4\n5")); } @Test public void supportArbitraryDelimiters() throws Exception { assertEquals(3, calculator.add("//;\n1;2")); assertEquals(7, calculator.add("//@\n3@4")); } @Test(expected = NegativesNotAllowed.class) public void negativesNotAllowed() throws Exception { calculator.add("//;\n1;2;-1"); } @Test(expected = NegativesNotAllowed.class) public void loneNegativeNotAllowed() throws Exception { calculator.add("-1"); } @Test public void ignoreNumbersGreaterThan1000() throws Exception { assertEquals(2, calculator.add("2,1003")); } @Test public void longerDelimiters() throws Exception { assertEquals(6, calculator.add("//[***]\n1***2***3")); } }