diff --git a/src/test/java/com/github/pedrovgs/problem28/FindSumsTest.java b/src/test/java/com/github/pedrovgs/problem28/FindSumsTest.java index 1132b328..eb25cbaa 100644 --- a/src/test/java/com/github/pedrovgs/problem28/FindSumsTest.java +++ b/src/test/java/com/github/pedrovgs/problem28/FindSumsTest.java @@ -20,7 +20,7 @@ import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Pedro Vicente Gómez Sánchez. @@ -96,4 +96,70 @@ public class FindSumsTest { assertTrue(result.contains(new Pair(9, -17))); } + + @Test public void shouldWorkWithBoundaryInputValues() { + int[][] inputArray = { + {Integer.MAX_VALUE, -2, -3, -4}, + {Integer.MIN_VALUE, 2, 3, 4}, + {Integer.MAX_VALUE - 1, -2, -3, -4}, + {Integer.MIN_VALUE + 1, 2, 3, 4}, + {(Integer.MIN_VALUE + Integer.MAX_VALUE) / 2, 0, 1, 2} + }; + int[] sumValues = { Integer.MAX_VALUE - 2, Integer.MIN_VALUE + 2, Integer.MAX_VALUE - 3, Integer.MIN_VALUE + 3, 0}; + + for (int i = 0; i < inputArray.length; i++) { + List> result = + findSums.findLinearComplexityOrder(inputArray[i], sumValues[i]); + + if (!result.contains(new Pair(inputArray[i][1], inputArray[i][0]))) { + fail("Fail test number " + i + 1); + } + } + + assertTrue(true); + } + + @Test public void shouldNotWorkWithBadInputValues() { + int[][] inputArray = { + {Integer.MAX_VALUE, 2, 3, 4}, + {Integer.MIN_VALUE, -2, 3, 4}, + {Integer.MAX_VALUE - 1, 2, 3, 4}, + {Integer.MIN_VALUE + 1, -2, -3, 4}, + {(Integer.MIN_VALUE + Integer.MAX_VALUE) / 2, 0, 1, 2} + }; + int[] sumValues = { Integer.MIN_VALUE + 1, Integer.MAX_VALUE - 1, Integer.MIN_VALUE, Integer.MAX_VALUE, 0}; + + for (int i = 0; i < inputArray.length; i++) { + List> result = + findSums.findLinearComplexityOrder(inputArray[i], sumValues[i]); + + if (result.contains(new Pair(inputArray[i][1], inputArray[i][0]))) { + fail("Fail test number " + i + 1); + } + } + + assertTrue(true); + } + + @Test public void shouldNotWorkWithOverflowNegativeSumValue() { + int[] inputArray = { Integer.MIN_VALUE, -1, 0, 1, 9 }; + int sumValue = Integer.MIN_VALUE - 1; + + List> result = + findSums.findLinearComplexityOrder(inputArray, sumValue); + + assertFalse("Should not allow overflow negative sum input", + result.contains(new Pair(-1, Integer.MIN_VALUE))); + } + + @Test public void shouldNotWorkWithOverflowPositiveSumValue() { + int[] inputArray = { Integer.MAX_VALUE, 1, 0, 1, 9 }; + int sumValue = Integer.MAX_VALUE + 1; + + List> result = + findSums.findLinearComplexityOrder(inputArray, sumValue); + + assertFalse("Should not allow overflow positive sum input", + result.contains(new Pair(1, Integer.MAX_VALUE))); + } } diff --git a/src/test/java/com/github/pedrovgs/problem45/FindNthMostRepeatedElementTest.java b/src/test/java/com/github/pedrovgs/problem45/FindNthMostRepeatedElementTest.java index 934446fa..aca62119 100644 --- a/src/test/java/com/github/pedrovgs/problem45/FindNthMostRepeatedElementTest.java +++ b/src/test/java/com/github/pedrovgs/problem45/FindNthMostRepeatedElementTest.java @@ -19,6 +19,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; /** * @author Pedro Vicente Gómez Sánchez.