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