Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
bit_vector_test.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/bit_vector.h"
6#include "platform/assert.h"
7#include "vm/unit_test.h"
8
9namespace dart {
10
11#define Z (thread->zone())
12
14 {
15 BitVector* v = new BitVector(Z, 15);
16 v->Add(1);
17 EXPECT_EQ(true, v->Contains(1));
18 EXPECT_EQ(false, v->Contains(0));
19 {
20 BitVector::Iterator iter(v);
21 EXPECT_EQ(1, iter.Current());
22 iter.Advance();
23 EXPECT(iter.Done());
24 }
25 v->Add(0);
26 v->Add(1);
27 EXPECT_EQ(true, v->Contains(0));
28 EXPECT_EQ(true, v->Contains(1));
29 {
30 BitVector::Iterator iter(v);
31 EXPECT_EQ(0, iter.Current());
32 iter.Advance();
33 EXPECT_EQ(1, iter.Current());
34 iter.Advance();
35 EXPECT(iter.Done());
36 }
37 }
38
39 {
40 BitVector* v = new BitVector(Z, 128);
41 v->Add(49);
42 v->Add(62);
43 v->Add(63);
44 v->Add(65);
45 EXPECT_EQ(true, v->Contains(49));
46 EXPECT_EQ(true, v->Contains(62));
47 EXPECT_EQ(true, v->Contains(63));
48 EXPECT_EQ(true, v->Contains(65));
49 EXPECT_EQ(false, v->Contains(64));
50 BitVector::Iterator iter(v);
51 EXPECT_EQ(49, iter.Current());
52 iter.Advance();
53 EXPECT_EQ(62, iter.Current());
54 iter.Advance();
55 EXPECT_EQ(63, iter.Current());
56 iter.Advance();
57 EXPECT_EQ(65, iter.Current());
58 iter.Advance();
59 EXPECT(iter.Done());
60 }
61
62 {
63 BitVector* a = new BitVector(Z, 128);
64 BitVector* b = new BitVector(Z, 128);
65 BitVector* c = new BitVector(Z, 128);
66 b->Add(0);
67 b->Add(32);
68 b->Add(64);
69 a->AddAll(b);
70 EXPECT_EQ(true, a->Contains(0));
71 EXPECT_EQ(true, a->Contains(32));
72 EXPECT_EQ(true, a->Contains(64));
73 EXPECT_EQ(false, a->Contains(96));
74 EXPECT_EQ(false, a->Contains(127));
75 b->Add(96);
76 b->Add(127);
77 c->Add(127);
78 a->KillAndAdd(c, b);
79 EXPECT_EQ(true, a->Contains(0));
80 EXPECT_EQ(true, a->Contains(32));
81 EXPECT_EQ(true, a->Contains(64));
82 EXPECT_EQ(true, a->Contains(96));
83 EXPECT_EQ(false, a->Contains(127));
84 a->Remove(0);
85 a->Remove(32);
86 a->Remove(64);
87 a->Remove(96);
88 EXPECT_EQ(false, a->Contains(0));
89 EXPECT_EQ(false, a->Contains(32));
90 EXPECT_EQ(false, a->Contains(64));
91 EXPECT_EQ(false, a->Contains(96));
92 }
93
94 {
95 BitVector* a = new BitVector(Z, 34);
96 BitVector* b = new BitVector(Z, 34);
97 a->SetAll();
98 b->Add(0);
99 b->Add(1);
100 b->Add(31);
101 b->Add(32);
102 a->Intersect(b);
103 EXPECT_EQ(true, a->Equals(*b));
104 }
105
106 {
107 BitVector* a = new BitVector(Z, 2);
108 BitVector* b = new BitVector(Z, 2);
109 a->SetAll();
110 a->Remove(0);
111 a->Remove(1);
112 EXPECT_EQ(true, a->Equals(*b));
113 }
114
115 {
116 BitVector* a = new BitVector(Z, 128);
117 BitVector* b = new BitVector(Z, 128);
118 b->Add(0);
119 b->Add(32);
120 b->Add(64);
121 a->Add(0);
122 a->Add(64);
123 b->RemoveAll(a);
124 EXPECT_EQ(false, b->Contains(0));
125 EXPECT_EQ(true, b->Contains(32));
126 EXPECT_EQ(false, b->Contains(64));
127 }
128}
129
130} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
#define Z
intptr_t Current() const
Definition bit_vector.h:33
void Add(intptr_t i)
Definition bit_vector.h:63
bool Contains(intptr_t i) const
Definition bit_vector.h:91
static bool b
struct MyStruct a[10]
#define TEST_CASE(name)
Definition unit_test.h:85