Advertisement
JeffGrigg

FindLargestProductTest

Aug 22nd, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.04 KB | None | 0 0
  1. import junit.framework.TestCase;
  2.  
  3. public class FindLargestProductTest extends TestCase {
  4.  
  5.     public void testOriginalCase() {
  6.         final int[] inputArray = {3, 6, -2, -5, 7, 3};
  7.         final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
  8.         assertEquals("7 * 3 = ", 21, largestProduct);
  9.     }
  10.  
  11.     public void testNegativeResult() {
  12.         final int[] inputArray = {3, -2, 6, -5, 7, -3};
  13.         final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
  14.         assertEquals("3 * -2 = ", -6, largestProduct);
  15.     }
  16.  
  17.     public void testTwoElementArray() {
  18.         final int[] inputArray = {3, 4};
  19.         final int largestProduct = FindLargestProduct.adjacentElementsProduct(inputArray);
  20.         assertEquals("3 * 4 = ", 12, largestProduct);
  21.     }
  22.  
  23.     public void testOneElementArray() {
  24.         final int[] inputArray = {6};
  25.         try {
  26.             //noinspection ResultOfMethodCallIgnored
  27.             FindLargestProduct.adjacentElementsProduct(inputArray);
  28.             fail("Expected IllegalArgumentException.");
  29.         } catch (final IllegalArgumentException ex) {
  30.             assertEquals("Minimum array size is two elements.", ex.getMessage());
  31.         }
  32.     }
  33.  
  34.     public void testEmptyInputArray() {
  35.         final int[] inputArray = {};
  36.         try {
  37.             //noinspection ResultOfMethodCallIgnored
  38.             FindLargestProduct.adjacentElementsProduct(inputArray);
  39.             fail("Expected IllegalArgumentException.");
  40.         } catch (final IllegalArgumentException ex) {
  41.             assertEquals("Minimum array size is two elements.", ex.getMessage());
  42.         }
  43.     }
  44.  
  45.     public void testNullInputArray() {
  46.         try {
  47.             //noinspection ResultOfMethodCallIgnored
  48.             FindLargestProduct.adjacentElementsProduct(null);
  49.             fail("Expected IllegalArgumentException.");
  50.         } catch (final IllegalArgumentException ex) {
  51.             assertEquals("Input array must not be null.", ex.getMessage());
  52.         }
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement