-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayShiftTest.java
More file actions
58 lines (47 loc) · 2.77 KB
/
Copy pathArrayShiftTest.java
File metadata and controls
58 lines (47 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ArrayShift;
import org.junit.Test;
import static ArrayShift.ArrayShift.insertShiftArray;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertArrayEquals;
public class ArrayShiftTest {
@Test
public void testOutputArrayLength() {
int[] arrayToTestEven = {1,2,3,4};
int[] arrayToTestOdd = {1,3,3,4,4};
int[] arrayToTestNoElement = {};
assertEquals("returned array should be one longer", arrayToTestEven.length + 1, insertShiftArray(arrayToTestEven, 5).length);
assertEquals("returned array should be one longer", arrayToTestOdd.length + 1, insertShiftArray(arrayToTestOdd, 5).length);
assertEquals("returned array should be one longer", arrayToTestNoElement.length + 1, insertShiftArray(arrayToTestNoElement, 5).length);
}
@Test
public void testArrayShift() {
int[] arrayToTestEven = {1,2,3,4};
int[] arrayToTestOdd = {1,3,3,4,4};
int[] arrayToTestNoElement = {};
int[] evenArrayToCompare = {1,2,3,3,4};
int[] oddArrayToCompare = {1,3,3,3,4,4};
int[] noElementArrayToCompare = {3};
int valueToInsert = 3;
assertArrayEquals("3 should be added to the center of the array", evenArrayToCompare, insertShiftArray(arrayToTestEven, valueToInsert));
assertArrayEquals("3 should be added to the center of the array", oddArrayToCompare, insertShiftArray(arrayToTestOdd, valueToInsert));
assertArrayEquals("3 should be added to the center of the array", noElementArrayToCompare, insertShiftArray(arrayToTestNoElement, valueToInsert));
}
@Test
public void testRemoveShiftArray() {
int[] arrayToTestEven = {1,2,3,4};
int[] arrayToTestOdd = {1,3,3,4,4};
int[] arrayToTestNoElement = {};
int[] arrayToTestOneElement = {1};
int[] arrayToTestTwoElements = {1,2};
int[] evenArrayToCompare = {1,2,4};
int[] oddArrayToCompare = {1,3,3,4};
int[] noElementArrayToCompare = {};
int[] oneElementArrayToCompare = {1};
int[] twoElementsArrayToCompare = {1};
assertArrayEquals("Arrays should be the same", evenArrayToCompare, ArrayShift.removeShiftArray(arrayToTestEven));
assertArrayEquals("Arrays should be the same", oddArrayToCompare, ArrayShift.removeShiftArray(arrayToTestOdd));
assertArrayEquals("Arrays should be the same", noElementArrayToCompare, ArrayShift.removeShiftArray(arrayToTestNoElement));
assertArrayEquals("Arrays should be the same", oneElementArrayToCompare, ArrayShift.removeShiftArray(arrayToTestOneElement));
assertArrayEquals("Arrays should be the same", twoElementsArrayToCompare, ArrayShift.removeShiftArray(arrayToTestTwoElements));
}
}