base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / gesture_detection / bitset_32_unittest.cc
blob2e5d2711e02567d54aee2202639ee818bceb46be
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/gesture_detection/bitset_32.h"
9 namespace ui {
11 class BitSet32Test : public testing::Test {};
13 TEST_F(BitSet32Test, Basic) {
14 BitSet32 bits;
16 // Test the empty set.
17 EXPECT_EQ(0U, bits.count());
18 EXPECT_TRUE(bits.is_empty());
19 EXPECT_FALSE(bits.is_full());
20 EXPECT_FALSE(bits.has_bit(0));
21 EXPECT_FALSE(bits.has_bit(31));
23 // Mark the first bit.
24 bits.mark_bit(0);
25 EXPECT_EQ(1U, bits.count());
26 EXPECT_FALSE(bits.is_empty());
27 EXPECT_FALSE(bits.is_full());
28 EXPECT_TRUE(bits.has_bit(0));
29 EXPECT_FALSE(bits.has_bit(31));
30 EXPECT_EQ(0U, bits.first_marked_bit());
31 EXPECT_EQ(0U, bits.last_marked_bit());
32 EXPECT_EQ(1U, bits.first_unmarked_bit());
34 // Mark the last bit.
35 bits.mark_bit(31);
36 EXPECT_EQ(2U, bits.count());
37 EXPECT_FALSE(bits.is_empty());
38 EXPECT_FALSE(bits.is_full());
39 EXPECT_TRUE(bits.has_bit(0));
40 EXPECT_TRUE(bits.has_bit(31));
41 EXPECT_FALSE(bits.has_bit(15));
42 EXPECT_EQ(0U, bits.first_marked_bit());
43 EXPECT_EQ(31U, bits.last_marked_bit());
44 EXPECT_EQ(1U, bits.first_unmarked_bit());
45 EXPECT_EQ(0U, bits.get_index_of_bit(0));
46 EXPECT_EQ(1U, bits.get_index_of_bit(1));
47 EXPECT_EQ(1U, bits.get_index_of_bit(2));
48 EXPECT_EQ(1U, bits.get_index_of_bit(31));
50 // Clear the first bit.
51 bits.clear_first_marked_bit();
52 EXPECT_EQ(1U, bits.count());
53 EXPECT_FALSE(bits.is_empty());
54 EXPECT_FALSE(bits.is_full());
55 EXPECT_FALSE(bits.has_bit(0));
56 EXPECT_TRUE(bits.has_bit(31));
57 EXPECT_EQ(31U, bits.first_marked_bit());
58 EXPECT_EQ(31U, bits.last_marked_bit());
59 EXPECT_EQ(0U, bits.first_unmarked_bit());
60 EXPECT_EQ(0U, bits.get_index_of_bit(0));
61 EXPECT_EQ(0U, bits.get_index_of_bit(1));
62 EXPECT_EQ(0U, bits.get_index_of_bit(31));
64 // Clear the last bit (the set should be empty).
65 bits.clear_last_marked_bit();
66 EXPECT_EQ(0U, bits.count());
67 EXPECT_TRUE(bits.is_empty());
68 EXPECT_FALSE(bits.is_full());
69 EXPECT_FALSE(bits.has_bit(0));
70 EXPECT_FALSE(bits.has_bit(31));
71 EXPECT_EQ(0U, bits.get_index_of_bit(0));
72 EXPECT_EQ(0U, bits.get_index_of_bit(31));
73 EXPECT_EQ(BitSet32(), bits);
75 // Mark the first unmarked bit (bit 0).
76 bits.mark_first_unmarked_bit();
77 EXPECT_EQ(1U, bits.count());
78 EXPECT_FALSE(bits.is_empty());
79 EXPECT_FALSE(bits.is_full());
80 EXPECT_TRUE(bits.has_bit(0));
81 EXPECT_EQ(0U, bits.first_marked_bit());
82 EXPECT_EQ(0U, bits.last_marked_bit());
83 EXPECT_EQ(1U, bits.first_unmarked_bit());
85 // Mark the next unmarked bit (bit 1).
86 bits.mark_first_unmarked_bit();
87 EXPECT_EQ(2U, bits.count());
88 EXPECT_FALSE(bits.is_empty());
89 EXPECT_FALSE(bits.is_full());
90 EXPECT_TRUE(bits.has_bit(0));
91 EXPECT_TRUE(bits.has_bit(1));
92 EXPECT_EQ(0U, bits.first_marked_bit());
93 EXPECT_EQ(1U, bits.last_marked_bit());
94 EXPECT_EQ(2U, bits.first_unmarked_bit());
95 EXPECT_EQ(0U, bits.get_index_of_bit(0));
96 EXPECT_EQ(1U, bits.get_index_of_bit(1));
97 EXPECT_EQ(2U, bits.get_index_of_bit(2));
100 } // namespace ui