Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some boundary tests #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
68 changes: 67 additions & 1 deletion src/test/java/com/github/pedrovgs/problem28/FindSumsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -96,4 +96,70 @@ public class FindSumsTest {

assertTrue(result.contains(new Pair<Integer, Integer>(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<Pair<Integer, Integer>> result =
findSums.findLinearComplexityOrder(inputArray[i], sumValues[i]);

if (!result.contains(new Pair<Integer, Integer>(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<Pair<Integer, Integer>> result =
findSums.findLinearComplexityOrder(inputArray[i], sumValues[i]);

if (result.contains(new Pair<Integer, Integer>(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<Pair<Integer, Integer>> result =
findSums.findLinearComplexityOrder(inputArray, sumValue);

assertFalse("Should not allow overflow negative sum input",
result.contains(new Pair<Integer, Integer>(-1, Integer.MIN_VALUE)));
}

@Test public void shouldNotWorkWithOverflowPositiveSumValue() {
int[] inputArray = { Integer.MAX_VALUE, 1, 0, 1, 9 };
int sumValue = Integer.MAX_VALUE + 1;

List<Pair<Integer, Integer>> result =
findSums.findLinearComplexityOrder(inputArray, sumValue);

assertFalse("Should not allow overflow positive sum input",
result.contains(new Pair<Integer, Integer>(1, Integer.MAX_VALUE)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down