Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- public class FindLargestProductTest extends TestCase {
- public void testOriginalCase() {
- final int[] inputArray = {3, 6, -2, -5, 7, 3};
- final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
- assertEquals("7 * 3 = ", 21, largestProduct);
- }
- public void testNegativeResult() {
- final int[] inputArray = {3, -2, 6, -5, 7, -3};
- final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
- assertEquals("3 * -2 = ", -6, largestProduct);
- }
- public void testTwoElementArray() {
- final int[] inputArray = {3, 4};
- final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
- assertEquals("3 * 4 = ", 12, largestProduct);
- }
- public void testOneElementArray() {
- final int[] inputArray = {6};
- try {
- //noinspection ResultOfMethodCallIgnored
- FindLargestProduct.adjacentElementsProduct(inputArray);
- fail("Expected IllegalArgumentException.");
- } catch (final IllegalArgumentException ex) {
- assertEquals("Minimum array size is two elements.", ex.getMessage());
- }
- }
- public void testEmptyInputArray() {
- final int[] inputArray = {};
- try {
- //noinspection ResultOfMethodCallIgnored
- FindLargestProduct.adjacentElementsProduct(inputArray);
- fail("Expected IllegalArgumentException.");
- } catch (final IllegalArgumentException ex) {
- assertEquals("Minimum array size is two elements.", ex.getMessage());
- }
- }
- public void testNullInputArray() {
- try {
- //noinspection ResultOfMethodCallIgnored
- FindLargestProduct.adjacentElementsProduct(null);
- fail("Expected IllegalArgumentException.");
- } catch (final IllegalArgumentException ex) {
- assertEquals("Input array must not be null.", ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement