Created
September 23, 2018 09:03
-
-
Save Wajahat-Jawaid/815da29116c18223ec365a3db745cea5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class RocketLogicTest { | |
Integer[] expectedArray = new Integer[]{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}; | |
@Test | |
public void testNullInput() throws IllegalArgumentException { | |
Assert.assertNull( | |
"Passing a null array returning null", | |
NestedArrayFlattener.flatten(null) | |
); | |
} | |
@Test | |
public void testEmptyArray() throws IllegalArgumentException { | |
Assert.assertArrayEquals( | |
"Passing empty array return the empty array", | |
new Integer[]{}, | |
NestedArrayFlattener.flatten(new Object[]{}) | |
); | |
} | |
@Test | |
public void testFlatArray() throws IllegalArgumentException { | |
Assert.assertArrayEquals( | |
"Flat array being passed, return the same array as that's already flattened", | |
expectedArray, | |
NestedArrayFlattener.flatten(new Object[]{1, 3, 5, 7, 9, 2, 4, 6, 8, 10}) | |
); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void throwsExceptionForObjectInArray() throws IllegalArgumentException { | |
NestedArrayFlattener.flatten( | |
new Object[]{new Object()} | |
); | |
} | |
@Test | |
public void testNestedArray() throws IllegalArgumentException { | |
Assert.assertArrayEquals( | |
"Nested array test with single nesting", | |
expectedArray, | |
NestedArrayFlattener.flatten(new Object[]{7, 1, 9, 13, new Object[]{23, 6, 24, 8}, 19, 100}) | |
); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void throwsExceptionForNullInNestedArray() throws IllegalArgumentException { | |
NestedArrayFlattener.flatten( | |
new Object[]{1, 2, new Object[]{3, null}} | |
); | |
} | |
@Test | |
public void testMultipleNestedArrays() throws IllegalArgumentException { | |
Assert.assertArrayEquals( | |
"Nested array test with multiple nestings", | |
expectedArray, | |
NestedArrayFlattener.flatten(new Object[]{1, new Object[]{3, 4, new Object[]{5}, 6, 7}, 2, 8, 9, 10}) | |
); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void throwsExceptionForObjectInNestedArray() throws IllegalArgumentException { | |
NestedArrayFlattener.flatten( | |
new Object[]{1, 2, new Object[]{3, new Object()}} | |
); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void throwsExceptionForNullInArray() throws IllegalArgumentException { | |
NestedArrayFlattener.flatten( | |
new Object[]{null} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment