-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_list_test.dart
66 lines (54 loc) · 1.59 KB
/
array_list_test.dart
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
59
60
61
62
63
64
65
66
import "package:test/test.dart";
import 'array_list.dart';
void main() {
test("Empty ArrayList should contain 0 elements", () {
ArrayList arr = new ArrayList();
expect(arr.length, equals(0));
});
test("ArrayList should support adding and retrieving elements", () {
ArrayList arr = new ArrayList<String>();
arr.add("Hello");
expect(arr.length, equals(1));
expect(arr[0], "Hello");
});
test("ArrayList should support adding many elements", () {
ArrayList arr = new ArrayList<int>();
for (int i = 0; i < 1000; i++) {
arr.add(i);
}
expect(arr.length, equals(1000));
expect(arr[0], 0);
expect(arr[999], 999);
});
test("ArrayList should implement Iterable", () {
ArrayList arr = new ArrayList<int>();
for (int i = 0; i < 1000; i++) {
arr.add(i);
}
expect(arr.first, equals(0));
expect(arr.last, equals(999));
expect(arr.reduce((value, element) => value + element), equals(499500));
});
test("ArrayList should support deletion", () {
ArrayList arr = new ArrayList<String>();
expect(arr.length, equals(0));
arr.add("😛");
arr.add("😅");
arr.remove(0);
expect(arr.length, equals(1));
expect(arr[0], equals("😅"));
});
test("ArrayList should auto shrink after deletion", () {
ArrayList arr = new ArrayList<int>();
for (int i = 0; i < 1000; i++) {
arr.add(i);
}
expect(arr.first, equals(0));
expect(arr.last, equals(999));
for (int i = 0; i < 998; i++) {
arr.remove(0);
}
expect(arr.first, equals(998));
expect(arr.last, equals(999));
});
}