Skip to content

Commit 9cce053

Browse files
committed
[test] Added test cases for sub list
1 parent fafd4da commit 9cce053

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tehreer-android/src/test/java/com/mta/tehreer/collections/IntListTestSuite.java

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public abstract class IntListTestSuite {
2727
protected IntList actual;
2828
protected int[] expected;
2929

30+
private static class SubListTestSuite extends IntListTestSuite {
31+
SubListTestSuite(IntList subList, int[] expected) {
32+
this.actual = subList;
33+
this.expected = expected;
34+
}
35+
}
36+
3037
protected IntListTestSuite() {
3138
}
3239

@@ -37,7 +44,8 @@ public void testSize() {
3744

3845
@Test
3946
public void testElements() {
40-
for (int i = 0; i < expected.length; i++) {
47+
int length = expected.length;
48+
for (int i = 0; i < length; i++) {
4149
assertEquals(actual.get(i), expected[i]);
4250
}
4351
}
@@ -82,6 +90,58 @@ public void testCopyAtEnd() {
8290
assertArrayEquals(copiedChunk, expected);
8391
}
8492

93+
private static void testSubList(IntList subList, int[] expected) {
94+
SubListTestSuite suite = new SubListTestSuite(subList, expected);
95+
suite.testSize();
96+
suite.testElements();
97+
suite.testCopyFull();
98+
suite.testCopyAtStart();
99+
suite.testCopyAtEnd();
100+
suite.testToArray();
101+
suite.testEquals();
102+
}
103+
104+
@Test
105+
public void testSubListEmpty() {
106+
int fullLength = expected.length;
107+
int halfLength = fullLength / 2;
108+
109+
testSubList(actual.subList(0, 0), new int[0]);
110+
testSubList(actual.subList(halfLength, halfLength), new int[0]);
111+
testSubList(actual.subList(fullLength, fullLength), new int[0]);
112+
}
113+
114+
@Test
115+
public void testSubListFirstHalf() {
116+
int firstStart = 0;
117+
int firstEnd = expected.length / 2;
118+
int[] firstHalf = Arrays.copyOfRange(expected, firstStart, firstEnd);
119+
IntList subList = actual.subList(firstStart, firstEnd);
120+
121+
testSubList(subList, firstHalf);
122+
}
123+
124+
@Test
125+
public void testSubListSecondHalf() {
126+
int secondStart = expected.length / 2;
127+
int secondEnd = expected.length;
128+
int[] secondHalf = Arrays.copyOfRange(expected, secondStart, secondEnd);
129+
IntList subList = actual.subList(secondStart, secondEnd);
130+
131+
testSubList(subList, secondHalf);
132+
}
133+
134+
@Test
135+
public void testSubListMidHalf() {
136+
int halfLength = expected.length / 2;
137+
int midStart = halfLength / 2;
138+
int midEnd = midStart + halfLength;
139+
int[] midHalf = Arrays.copyOfRange(expected, midStart, midEnd);
140+
IntList subList = actual.subList(midStart, midEnd);
141+
142+
testSubList(subList, midHalf);
143+
}
144+
85145
@Test
86146
public void testToArray() {
87147
assertArrayEquals(actual.toArray(), expected);

0 commit comments

Comments
 (0)