forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordBitSet.cpp
More file actions
75 lines (57 loc) · 1.4 KB
/
WordBitSet.cpp
File metadata and controls
75 lines (57 loc) · 1.4 KB
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "gtest/gtest.h"
#include "hermes/ADT/WordBitSet.h"
using namespace hermes;
namespace {
TEST(WordBitSet, SmokeTest) {
WordBitSet<uint32_t> s{};
ASSERT_TRUE(s.empty());
ASSERT_TRUE(s.begin() == s.end());
s.set(0);
s.set(1);
s.set(20);
s.set(31);
for (unsigned i = 0; i < 32; ++i) {
bool b1 = s.at(i);
bool b2 = s[i];
ASSERT_EQ(b1, b2);
ASSERT_EQ(i == 0 || i == 1 || i == 20 || i == 31, b2);
}
ASSERT_EQ(0, s.findFirst());
ASSERT_EQ(0, s.findFirst());
ASSERT_EQ(1, s.findNext(0));
ASSERT_EQ(1, s.findNext(0));
ASSERT_EQ(20, s.findNext(1));
ASSERT_EQ(20, s.findNext(1));
ASSERT_EQ(31, s.findNext(20));
ASSERT_EQ(31, s.findNext(20));
ASSERT_EQ(-1, s.findNext(31));
ASSERT_EQ(-1, s.findNext(31));
ASSERT_EQ(20, s.findNext(5));
auto it = s.begin();
auto end = s.end();
ASSERT_TRUE(end == s.end());
ASSERT_TRUE(it != end);
ASSERT_EQ(0, *it);
ASSERT_EQ(0, *it);
++it;
ASSERT_TRUE(it != end);
ASSERT_EQ(1, *it);
ASSERT_EQ(1, *it);
++it;
ASSERT_TRUE(it != end);
ASSERT_EQ(20, *it);
ASSERT_EQ(20, *it);
++it;
ASSERT_TRUE(it != end);
ASSERT_EQ(31, *it);
ASSERT_EQ(31, *it);
++it;
ASSERT_TRUE(it == end);
}
} // anonymous namespace