OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 namespace bin { | 10 namespace bin { |
11 | 11 |
12 VM_UNIT_TEST_CASE(CircularLinkedList) { | 12 VM_UNIT_TEST_CASE(CircularLinkedList) { |
13 CircularLinkedList<int> list; | 13 CircularLinkedList<int> list; |
14 | 14 |
15 EXPECT(!list.HasHead()); | 15 EXPECT(!list.HasHead()); |
16 | 16 |
17 list.Add(1); | 17 list.Add(1); |
18 EXPECT(list.HasHead()); | 18 EXPECT(list.HasHead()); |
19 EXPECT(list.head() == 1); | 19 EXPECT(list.head() == 1); |
20 | 20 |
21 | |
22 // Test: Inserts don't move head. | 21 // Test: Inserts don't move head. |
23 for (int i = 2; i <= 100; i++) { | 22 for (int i = 2; i <= 100; i++) { |
24 list.Add(i); | 23 list.Add(i); |
25 EXPECT(list.head() == 1); | 24 EXPECT(list.head() == 1); |
26 } | 25 } |
27 | 26 |
28 | |
29 // Test: Rotate cycle through all elements in insertion order. | 27 // Test: Rotate cycle through all elements in insertion order. |
30 for (int i = 1; i <= 100; i++) { | 28 for (int i = 1; i <= 100; i++) { |
31 EXPECT(list.HasHead()); | 29 EXPECT(list.HasHead()); |
32 EXPECT(list.head() == i); | 30 EXPECT(list.head() == i); |
33 list.Rotate(); | 31 list.Rotate(); |
34 } | 32 } |
35 | 33 |
36 | |
37 // Test: Removing head results in next element to be head. | 34 // Test: Removing head results in next element to be head. |
38 for (int i = 1; i <= 100; i++) { | 35 for (int i = 1; i <= 100; i++) { |
39 list.RemoveHead(); | 36 list.RemoveHead(); |
40 for (int j = i + 1; j <= 100; j++) { | 37 for (int j = i + 1; j <= 100; j++) { |
41 EXPECT(list.HasHead()); | 38 EXPECT(list.HasHead()); |
42 EXPECT(list.head() == j); | 39 EXPECT(list.head() == j); |
43 list.Rotate(); | 40 list.Rotate(); |
44 } | 41 } |
45 } | 42 } |
46 | 43 |
47 // Test: Removing all items individually make list empty. | 44 // Test: Removing all items individually make list empty. |
48 EXPECT(!list.HasHead()); | 45 EXPECT(!list.HasHead()); |
49 | 46 |
50 | |
51 // Test: Removing all items at once makes list empty. | 47 // Test: Removing all items at once makes list empty. |
52 for (int i = 1; i <= 100; i++) { | 48 for (int i = 1; i <= 100; i++) { |
53 list.Add(i); | 49 list.Add(i); |
54 } | 50 } |
55 list.RemoveAll(); | 51 list.RemoveAll(); |
56 EXPECT(!list.HasHead()); | 52 EXPECT(!list.HasHead()); |
57 | 53 |
58 | |
59 // Test: Remove individual items just deletes them without modifying head. | 54 // Test: Remove individual items just deletes them without modifying head. |
60 for (int i = 1; i <= 10; i++) { | 55 for (int i = 1; i <= 10; i++) { |
61 list.Add(i); | 56 list.Add(i); |
62 } | 57 } |
63 for (int i = 2; i <= 9; i++) { | 58 for (int i = 2; i <= 9; i++) { |
64 list.Remove(i); | 59 list.Remove(i); |
65 } | 60 } |
66 EXPECT(list.head() == 1); | 61 EXPECT(list.head() == 1); |
67 list.Rotate(); | 62 list.Rotate(); |
68 EXPECT(list.head() == 10); | 63 EXPECT(list.head() == 10); |
69 list.Rotate(); | 64 list.Rotate(); |
70 EXPECT(list.head() == 1); | 65 EXPECT(list.head() == 1); |
71 | 66 |
72 | |
73 // Test: Remove non-existent element leaves list un-changed. | 67 // Test: Remove non-existent element leaves list un-changed. |
74 list.Remove(4242); | 68 list.Remove(4242); |
75 EXPECT(list.head() == 1); | 69 EXPECT(list.head() == 1); |
76 | 70 |
77 | |
78 // Test: Remove head element individually moves head to next element. | 71 // Test: Remove head element individually moves head to next element. |
79 list.Remove(1); | 72 list.Remove(1); |
80 EXPECT(list.HasHead()); | 73 EXPECT(list.HasHead()); |
81 EXPECT(list.head() == 10); | 74 EXPECT(list.head() == 10); |
82 list.Remove(10); | 75 list.Remove(10); |
83 EXPECT(!list.HasHead()); | 76 EXPECT(!list.HasHead()); |
84 | 77 |
85 | |
86 // Test: Remove non-existent element from empty list works. | 78 // Test: Remove non-existent element from empty list works. |
87 list.Remove(4242); | 79 list.Remove(4242); |
88 } | 80 } |
89 | 81 |
90 } // namespace bin | 82 } // namespace bin |
91 } // namespace dart | 83 } // namespace dart |
OLD | NEW |