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

Side by Side Diff: runtime/vm/bit_vector_test.cc

Issue 868913002: Add Zone-based handle allocation interface and reduce use of Isolate-based interfaces. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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
« no previous file with comments | « runtime/vm/bit_vector.h ('k') | runtime/vm/code_descriptors_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bit_vector.h" 6 #include "vm/bit_vector.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
11 #define I Isolate::Current() 11 #define Z Thread::Current()->zone()
12 12
13 TEST_CASE(BitVector) { 13 TEST_CASE(BitVector) {
14 { BitVector* v = new BitVector(I, 15); 14 { BitVector* v = new BitVector(Z, 15);
15 v->Add(1); 15 v->Add(1);
16 EXPECT_EQ(true, v->Contains(1)); 16 EXPECT_EQ(true, v->Contains(1));
17 EXPECT_EQ(false, v->Contains(0)); 17 EXPECT_EQ(false, v->Contains(0));
18 { BitVector::Iterator iter(v); 18 { BitVector::Iterator iter(v);
19 EXPECT_EQ(1, iter.Current()); 19 EXPECT_EQ(1, iter.Current());
20 iter.Advance(); 20 iter.Advance();
21 EXPECT(iter.Done()); 21 EXPECT(iter.Done());
22 } 22 }
23 v->Add(0); 23 v->Add(0);
24 v->Add(1); 24 v->Add(1);
25 EXPECT_EQ(true, v->Contains(0)); 25 EXPECT_EQ(true, v->Contains(0));
26 EXPECT_EQ(true, v->Contains(1)); 26 EXPECT_EQ(true, v->Contains(1));
27 { BitVector::Iterator iter(v); 27 { BitVector::Iterator iter(v);
28 EXPECT_EQ(0, iter.Current()); 28 EXPECT_EQ(0, iter.Current());
29 iter.Advance(); 29 iter.Advance();
30 EXPECT_EQ(1, iter.Current()); 30 EXPECT_EQ(1, iter.Current());
31 iter.Advance(); 31 iter.Advance();
32 EXPECT(iter.Done()); 32 EXPECT(iter.Done());
33 } 33 }
34 } 34 }
35 35
36 { BitVector* v = new BitVector(I, 128); 36 { BitVector* v = new BitVector(Z, 128);
37 v->Add(49); 37 v->Add(49);
38 v->Add(62); 38 v->Add(62);
39 v->Add(63); 39 v->Add(63);
40 v->Add(65); 40 v->Add(65);
41 EXPECT_EQ(true, v->Contains(49)); 41 EXPECT_EQ(true, v->Contains(49));
42 EXPECT_EQ(true, v->Contains(62)); 42 EXPECT_EQ(true, v->Contains(62));
43 EXPECT_EQ(true, v->Contains(63)); 43 EXPECT_EQ(true, v->Contains(63));
44 EXPECT_EQ(true, v->Contains(65)); 44 EXPECT_EQ(true, v->Contains(65));
45 EXPECT_EQ(false, v->Contains(64)); 45 EXPECT_EQ(false, v->Contains(64));
46 BitVector::Iterator iter(v); 46 BitVector::Iterator iter(v);
47 EXPECT_EQ(49, iter.Current()); 47 EXPECT_EQ(49, iter.Current());
48 iter.Advance(); 48 iter.Advance();
49 EXPECT_EQ(62, iter.Current()); 49 EXPECT_EQ(62, iter.Current());
50 iter.Advance(); 50 iter.Advance();
51 EXPECT_EQ(63, iter.Current()); 51 EXPECT_EQ(63, iter.Current());
52 iter.Advance(); 52 iter.Advance();
53 EXPECT_EQ(65, iter.Current()); 53 EXPECT_EQ(65, iter.Current());
54 iter.Advance(); 54 iter.Advance();
55 EXPECT(iter.Done()); 55 EXPECT(iter.Done());
56 } 56 }
57 57
58 { BitVector* a = new BitVector(I, 128); 58 { BitVector* a = new BitVector(Z, 128);
59 BitVector* b = new BitVector(I, 128); 59 BitVector* b = new BitVector(Z, 128);
60 BitVector* c = new BitVector(I, 128); 60 BitVector* c = new BitVector(Z, 128);
61 b->Add(0); 61 b->Add(0);
62 b->Add(32); 62 b->Add(32);
63 b->Add(64); 63 b->Add(64);
64 a->AddAll(b); 64 a->AddAll(b);
65 EXPECT_EQ(true, a->Contains(0)); 65 EXPECT_EQ(true, a->Contains(0));
66 EXPECT_EQ(true, a->Contains(32)); 66 EXPECT_EQ(true, a->Contains(32));
67 EXPECT_EQ(true, a->Contains(64)); 67 EXPECT_EQ(true, a->Contains(64));
68 EXPECT_EQ(false, a->Contains(96)); 68 EXPECT_EQ(false, a->Contains(96));
69 EXPECT_EQ(false, a->Contains(127)); 69 EXPECT_EQ(false, a->Contains(127));
70 b->Add(96); 70 b->Add(96);
71 b->Add(127); 71 b->Add(127);
72 c->Add(127); 72 c->Add(127);
73 a->KillAndAdd(c, b); 73 a->KillAndAdd(c, b);
74 EXPECT_EQ(true, a->Contains(0)); 74 EXPECT_EQ(true, a->Contains(0));
75 EXPECT_EQ(true, a->Contains(32)); 75 EXPECT_EQ(true, a->Contains(32));
76 EXPECT_EQ(true, a->Contains(64)); 76 EXPECT_EQ(true, a->Contains(64));
77 EXPECT_EQ(true, a->Contains(96)); 77 EXPECT_EQ(true, a->Contains(96));
78 EXPECT_EQ(false, a->Contains(127)); 78 EXPECT_EQ(false, a->Contains(127));
79 a->Remove(0); 79 a->Remove(0);
80 a->Remove(32); 80 a->Remove(32);
81 a->Remove(64); 81 a->Remove(64);
82 a->Remove(96); 82 a->Remove(96);
83 EXPECT_EQ(false, a->Contains(0)); 83 EXPECT_EQ(false, a->Contains(0));
84 EXPECT_EQ(false, a->Contains(32)); 84 EXPECT_EQ(false, a->Contains(32));
85 EXPECT_EQ(false, a->Contains(64)); 85 EXPECT_EQ(false, a->Contains(64));
86 EXPECT_EQ(false, a->Contains(96)); 86 EXPECT_EQ(false, a->Contains(96));
87 } 87 }
88 88
89 { BitVector* a = new BitVector(I, 34); 89 { BitVector* a = new BitVector(Z, 34);
90 BitVector* b = new BitVector(I, 34); 90 BitVector* b = new BitVector(Z, 34);
91 a->SetAll(); 91 a->SetAll();
92 b->Add(0); 92 b->Add(0);
93 b->Add(1); 93 b->Add(1);
94 b->Add(31); 94 b->Add(31);
95 b->Add(32); 95 b->Add(32);
96 a->Intersect(b); 96 a->Intersect(b);
97 EXPECT_EQ(true, a->Equals(*b)); 97 EXPECT_EQ(true, a->Equals(*b));
98 } 98 }
99 99
100 { BitVector* a = new BitVector(I, 2); 100 { BitVector* a = new BitVector(Z, 2);
101 BitVector* b = new BitVector(I, 2); 101 BitVector* b = new BitVector(Z, 2);
102 a->SetAll(); 102 a->SetAll();
103 a->Remove(0); 103 a->Remove(0);
104 a->Remove(1); 104 a->Remove(1);
105 EXPECT_EQ(true, a->Equals(*b)); 105 EXPECT_EQ(true, a->Equals(*b));
106 } 106 }
107 107
108 { BitVector* a = new BitVector(I, 128); 108 { BitVector* a = new BitVector(Z, 128);
109 BitVector* b = new BitVector(I, 128); 109 BitVector* b = new BitVector(Z, 128);
110 b->Add(0); 110 b->Add(0);
111 b->Add(32); 111 b->Add(32);
112 b->Add(64); 112 b->Add(64);
113 a->Add(0); 113 a->Add(0);
114 a->Add(64); 114 a->Add(64);
115 b->RemoveAll(a); 115 b->RemoveAll(a);
116 EXPECT_EQ(false, b->Contains(0)); 116 EXPECT_EQ(false, b->Contains(0));
117 EXPECT_EQ(true, b->Contains(32)); 117 EXPECT_EQ(true, b->Contains(32));
118 EXPECT_EQ(false, b->Contains(64)); 118 EXPECT_EQ(false, b->Contains(64));
119 } 119 }
120 } 120 }
121 121
122 } // namespace dart 122 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bit_vector.h ('k') | runtime/vm/code_descriptors_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698