Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Unified Diff: dart/runtime/bin/eventhandler_test.cc

Issue 914203002: Add unittest for CircularLinkedList + bugfix (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/runtime/bin/eventhandler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/runtime/bin/eventhandler_test.cc
diff --git a/dart/runtime/bin/eventhandler_test.cc b/dart/runtime/bin/eventhandler_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4644bddeaf11ae9a56e198267eb40a521b420dd
--- /dev/null
+++ b/dart/runtime/bin/eventhandler_test.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/assert.h"
+#include "platform/globals.h"
+#include "vm/unit_test.h"
+
+#include "bin/eventhandler.h"
+
+namespace dart {
+namespace bin {
+
+UNIT_TEST_CASE(CircularLinkedList) {
+ CircularLinkedList<int> list;
+
+ EXPECT(!list.HasHead());
+
+ list.Add(1);
+ EXPECT(list.HasHead());
+ EXPECT(list.head() == 1);
+
+
+ // Test: Inserts don't move head.
+ for (int i = 2; i <= 100; i++) {
+ list.Add(i);
+ EXPECT(list.head() == 1);
+ }
+
+
+ // Test: Rotate cycle through all elements in insertion order.
+ for (int i = 1; i <= 100; i++) {
+ EXPECT(list.HasHead());
+ EXPECT(list.head() == i);
+ list.Rotate();
+ }
+
+
+ // Test: Removing head results in next element to be head.
+ for (int i = 1; i <= 100; i++) {
+ list.RemoveHead();
+ for (int j = i + 1; j <= 100; j++) {
+ EXPECT(list.HasHead());
+ EXPECT(list.head() == j);
+ list.Rotate();
+ }
+ }
+
+ // Test: Removing all items individually make list empty.
+ EXPECT(!list.HasHead());
+
+
+ // 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.
+ for (int i = 1; i <= 100; i++) {
+ list.Add(i);
+ }
+ list.RemoveAll();
+ EXPECT(!list.HasHead());
+
+
+ // Test: Remove individual items just deletes them without modifying head.
+ for (int i = 1; i <= 10; i++) {
+ list.Add(i);
+ }
+ for (int i = 2; i <= 9; i++) {
+ list.Remove(i);
+ }
+ EXPECT(list.head() == 1);
+ list.Rotate();
+ EXPECT(list.head() == 10);
+ list.Rotate();
+ EXPECT(list.head() == 1);
+
+
+ // Test: Remove non-existent element leaves list un-changed.
+ list.Remove(4242);
+ EXPECT(list.head() == 1);
+
+
+ // Test: Remove head element individually moves head to next element.
+ list.Remove(1);
+ EXPECT(list.HasHead());
+ EXPECT(list.head() == 10);
+ list.Remove(10);
+ EXPECT(!list.HasHead());
+
+
+ // Test: Remove non-existent element from empty list works.
+ list.Remove(4242);
+}
+
+} // namespace bin
+} // namespace dart
« no previous file with comments | « dart/runtime/bin/eventhandler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698