package test; import static org.junit.Assert.assertEquals; import static test.TestData.ZERO_LENGTH_MATRIX; import static test.TestData.MATRIX; import static test.TestData.SOLUTION; import org.junit.Before; import org.junit.Test; import maxtrix.MatrixNthSmallest; public class MatrixNthSmallestTest { MatrixNthSmallest nthSmallestValueGenerator; @Before public void setUp() { nthSmallestValueGenerator = new MatrixNthSmallest(); } @Test(expected = IllegalArgumentException.class) public void nullMatrixNotAllowed() { nthSmallestValueGenerator.getNthSmallestValue(null, 1); } @Test(expected = IllegalArgumentException.class) public void zeroLengthOfMatrixNotAllowed() { nthSmallestValueGenerator.getNthSmallestValue(ZERO_LENGTH_MATRIX, 1); } @Test(expected = IllegalArgumentException.class) public void invalidNValueNotAllowed() { nthSmallestValueGenerator.getNthSmallestValue(MATRIX, 0); } @Test public void expectedResultVerified() { for(int i = 1; i <= MATRIX.length * MATRIX[0].length; i++) { assertEquals(nthSmallestValueGenerator.getNthSmallestValue(MATRIX, i), SOLUTION[i-1]); } } }