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

Unified Diff: packages/barback/test/multiset_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
Index: packages/barback/test/multiset_test.dart
diff --git a/packages/barback/test/multiset_test.dart b/packages/barback/test/multiset_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7b6f09f577b745e191179907163214512686981f
--- /dev/null
+++ b/packages/barback/test/multiset_test.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2013, 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.
+
+library barback.test.multiset_test;
+
+import 'package:barback/src/utils/multiset.dart';
+import 'package:unittest/unittest.dart';
+
+import 'utils.dart';
+
+main() {
+ initConfig();
+
+ test("new Multiset() creates an empty set", () {
+ var multiSet = new Multiset();
+ expect(multiSet, isEmpty);
+ expect(multiSet.contains(1), isFalse);
+ expect(multiSet.count(1), equals(0));
+ });
+
+ test("new Multiset.from(...) constructs a set from the argument", () {
+ var multiSet = new Multiset.from([1, 2, 3, 2, 4]);
+ expect(multiSet.toList(), equals([1, 2, 2, 3, 4]));
+ expect(multiSet.contains(1), isTrue);
+ expect(multiSet.contains(5), isFalse);
+ expect(multiSet.count(1), equals(1));
+ expect(multiSet.count(2), equals(2));
+ expect(multiSet.count(5), equals(0));
+ });
+
+ test("an element can be added and removed once", () {
+ var multiSet = new Multiset();
+ expect(multiSet.contains(1), isFalse);
+ multiSet.add(1);
+ expect(multiSet.contains(1), isTrue);
+ multiSet.remove(1);
+ expect(multiSet.contains(1), isFalse);
+ });
+
+ test("a set can contain multiple copies of an element", () {
+ var multiSet = new Multiset();
+ expect(multiSet.count(1), equals(0));
+ multiSet.add(1);
+ expect(multiSet.count(1), equals(1));
+ multiSet.add(1);
+ expect(multiSet.count(1), equals(2));
+ multiSet.remove(1);
+ expect(multiSet.count(1), equals(1));
+ multiSet.remove(1);
+ expect(multiSet.count(1), equals(0));
+ });
+
+ test("remove returns false if the element wasn't in the set", () {
+ var multiSet = new Multiset();
+ expect(multiSet.remove(1), isFalse);
+ });
+
+ test("remove returns true if the element was in the set", () {
+ var multiSet = new Multiset.from([1]);
+ expect(multiSet.remove(1), isTrue);
+ });
+
+ test("remove returns true if the element was in the set even if more copies "
+ "remain", () {
+ var multiSet = new Multiset.from([1, 1, 1]);
+ expect(multiSet.remove(1), isTrue);
+ });
+
+ test("iterator orders distinct elements in insertion order", () {
+ var multiSet = new Multiset()..add(1)..add(2)..add(3)..add(4)..add(5);
+ expect(multiSet.toList(), equals([1, 2, 3, 4, 5]));
+ });
+
+ test("iterator groups multiple copies of an element together", () {
+ var multiSet = new Multiset()..add(1)..add(2)..add(1)..add(2)..add(1);
+ expect(multiSet.toList(), equals([1, 1, 1, 2, 2]));
+ });
+}
« no previous file with comments | « packages/barback/test/logger_test.dart ('k') | packages/barback/test/package_graph/add_remove_transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698