Skip to content

Commit aee7594

Browse files
committed
Tests for ArrayList
1 parent 5b9f211 commit aee7594

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎IntensiveCourse/Lesson1/Main.java‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package IntensiveCourse.Lesson1;
2+
3+
import java.util.ArrayList;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) {
8+
9+
System.out.println("START");
10+
11+
MyArrayList<Integer> list = new MyArrayList<Integer>();
12+
13+
for (int i = 0; i < 5; i++) {
14+
list.add(i);
15+
}
16+
17+
// add test
18+
System.out.println(list.size() == 5);
19+
System.out.println(list.get(4) == 4);
20+
21+
// add at index test
22+
list.add(4,777);
23+
System.out.println(list.size() == 6);
24+
System.out.println(list.get(4) == 777);
25+
26+
// set test
27+
list.set(4, 666);
28+
System.out.println(list.size() == 6);
29+
System.out.println(list.get(4) == 666);
30+
31+
// index of test
32+
System.out.println(list.indexOf(666) == 4);
33+
34+
// remove by index test
35+
System.out.println(list.remove(4) == 666);
36+
System.out.println(list.size() == 5);
37+
38+
// remove object that exist test
39+
list.add(2,777);
40+
System.out.println(list.remove((Object) 777));
41+
System.out.println(list.get(2) == 2);
42+
System.out.println(list.size() == 5);
43+
44+
// remove object that doesn't exist test
45+
System.out.println(!list.remove((Object) 777));
46+
System.out.println(list.get(2) == 2);
47+
System.out.println(list.size() == 5);
48+
49+
System.out.println("DONE");
50+
}
51+
}

0 commit comments

Comments
 (0)