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

Side by Side Diff: tests/compiler/dart2js/setlet_test.dart

Issue 27510002: Add a much simplified set implementation designed to waste little memory for small sets. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import "package:expect/expect.dart";
6 import '../../../sdk/lib/_internal/compiler/implementation/util/setlet.dart';
7
8 main() {
9 for (int i = 1; i <= 32; i++) {
10 test(i);
11 }
12 }
13
14 test(int size) {
15 var setlet = new Setlet();
16 for (int i = 0; i < size; i++) {
17 Expect.isTrue(setlet.isEmpty == (i == 0));
18 setlet.add(i);
19 Expect.equals(i + 1, setlet.length);
20 Expect.isFalse(setlet.isEmpty);
21 for (int j = 0; j < size + size; j++) {
22 Expect.isTrue(setlet.contains(j) == (j <= i));
23 }
24 Expect.isTrue(setlet.remove(i));
25 Expect.isFalse(setlet.remove(i + 1));
26 setlet.add(i);
27
28 List expectedElements = [];
29 for (int j = 0; j <= i; j++) expectedElements.add(j);
30
31 List actualElements = [];
32 setlet.forEach((each) => actualElements.add(each));
33 Expect.listEquals(expectedElements, actualElements);
34
35 actualElements = [];
36 for (var each in setlet) actualElements.add(each);
37 Expect.listEquals(expectedElements, actualElements);
38 }
39
40 for (int i = 0; i < size; i++) {
41 Expect.equals(size, setlet.length);
42
43 // Try removing all possible ranges one by one and re-add them.
44 for (int k = size; k > i; --k) {
45 for (int j = i; j < k; j++) {
46 Expect.isTrue(setlet.remove(j));
47 Expect.equals(size - (j - i + 1), setlet.length);
48 Expect.isFalse(setlet.remove(j));
49 Expect.isFalse(setlet.contains(j));
50 }
51
52 for (int j = i; j < k; j++) {
53 setlet.add(j);
54 }
55 }
56
57 Expect.equals(size, setlet.length);
58 Expect.isTrue(setlet.contains(i));
59 }
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698