-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbit_vector_test.cc
130 lines (120 loc) · 3.07 KB
/
bit_vector_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 "vm/bit_vector.h"
#include "platform/assert.h"
#include "vm/unit_test.h"
namespace dart {
#define Z (thread->zone())
TEST_CASE(BitVector) {
{
BitVector* v = new BitVector(Z, 15);
v->Add(1);
EXPECT_EQ(true, v->Contains(1));
EXPECT_EQ(false, v->Contains(0));
{
BitVector::Iterator iter(v);
EXPECT_EQ(1, iter.Current());
iter.Advance();
EXPECT(iter.Done());
}
v->Add(0);
v->Add(1);
EXPECT_EQ(true, v->Contains(0));
EXPECT_EQ(true, v->Contains(1));
{
BitVector::Iterator iter(v);
EXPECT_EQ(0, iter.Current());
iter.Advance();
EXPECT_EQ(1, iter.Current());
iter.Advance();
EXPECT(iter.Done());
}
}
{
BitVector* v = new BitVector(Z, 128);
v->Add(49);
v->Add(62);
v->Add(63);
v->Add(65);
EXPECT_EQ(true, v->Contains(49));
EXPECT_EQ(true, v->Contains(62));
EXPECT_EQ(true, v->Contains(63));
EXPECT_EQ(true, v->Contains(65));
EXPECT_EQ(false, v->Contains(64));
BitVector::Iterator iter(v);
EXPECT_EQ(49, iter.Current());
iter.Advance();
EXPECT_EQ(62, iter.Current());
iter.Advance();
EXPECT_EQ(63, iter.Current());
iter.Advance();
EXPECT_EQ(65, iter.Current());
iter.Advance();
EXPECT(iter.Done());
}
{
BitVector* a = new BitVector(Z, 128);
BitVector* b = new BitVector(Z, 128);
BitVector* c = new BitVector(Z, 128);
b->Add(0);
b->Add(32);
b->Add(64);
a->AddAll(b);
EXPECT_EQ(true, a->Contains(0));
EXPECT_EQ(true, a->Contains(32));
EXPECT_EQ(true, a->Contains(64));
EXPECT_EQ(false, a->Contains(96));
EXPECT_EQ(false, a->Contains(127));
b->Add(96);
b->Add(127);
c->Add(127);
a->KillAndAdd(c, b);
EXPECT_EQ(true, a->Contains(0));
EXPECT_EQ(true, a->Contains(32));
EXPECT_EQ(true, a->Contains(64));
EXPECT_EQ(true, a->Contains(96));
EXPECT_EQ(false, a->Contains(127));
a->Remove(0);
a->Remove(32);
a->Remove(64);
a->Remove(96);
EXPECT_EQ(false, a->Contains(0));
EXPECT_EQ(false, a->Contains(32));
EXPECT_EQ(false, a->Contains(64));
EXPECT_EQ(false, a->Contains(96));
}
{
BitVector* a = new BitVector(Z, 34);
BitVector* b = new BitVector(Z, 34);
a->SetAll();
b->Add(0);
b->Add(1);
b->Add(31);
b->Add(32);
a->Intersect(b);
EXPECT_EQ(true, a->Equals(*b));
}
{
BitVector* a = new BitVector(Z, 2);
BitVector* b = new BitVector(Z, 2);
a->SetAll();
a->Remove(0);
a->Remove(1);
EXPECT_EQ(true, a->Equals(*b));
}
{
BitVector* a = new BitVector(Z, 128);
BitVector* b = new BitVector(Z, 128);
b->Add(0);
b->Add(32);
b->Add(64);
a->Add(0);
a->Add(64);
b->RemoveAll(a);
EXPECT_EQ(false, b->Contains(0));
EXPECT_EQ(true, b->Contains(32));
EXPECT_EQ(false, b->Contains(64));
}
}
} // namespace dart