blob: 5894de2a82cf793ba10c6988b1c2a42c90365d42 [file] [log] [blame]
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00001// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include <stdlib.h>
29
30#include "v8.h"
31
32#include "data-flow.h"
33#include "cctest.h"
34
35using namespace v8::internal;
36
37TEST(BitVector) {
38 ZoneScope zone(DELETE_ON_EXIT);
39 {
40 BitVector v(15);
41 v.Add(1);
42 CHECK(v.Contains(1));
43 v.Remove(0);
44 CHECK(!v.Contains(0));
45 v.Add(0);
46 v.Add(1);
47 BitVector w(15);
48 w.Add(1);
49 v.Intersect(w);
50 CHECK(!v.Contains(0));
51 CHECK(v.Contains(1));
52 }
53
54 {
kasperl@chromium.orga5551262010-12-07 12:49:48 +000055 BitVector v(64);
56 v.Add(27);
57 v.Add(30);
58 v.Add(31);
59 v.Add(33);
60 BitVector::Iterator iter(&v);
61 CHECK_EQ(27, iter.Current());
62 iter.Advance();
63 CHECK_EQ(30, iter.Current());
64 iter.Advance();
65 CHECK_EQ(31, iter.Current());
66 iter.Advance();
67 CHECK_EQ(33, iter.Current());
68 iter.Advance();
69 CHECK(iter.Done());
70 }
71
72 {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000073 BitVector v(15);
74 v.Add(0);
75 BitVector w(15);
76 w.Add(1);
77 v.Union(w);
78 CHECK(v.Contains(0));
79 CHECK(v.Contains(1));
80 }
81
82 {
83 BitVector v(15);
84 v.Add(0);
85 BitVector w(15);
86 w = v;
87 CHECK(w.Contains(0));
88 w.Add(1);
89 BitVector u(w);
90 CHECK(u.Contains(0));
91 CHECK(u.Contains(1));
92 v.Union(w);
93 CHECK(v.Contains(0));
94 CHECK(v.Contains(1));
95 }
96
97 {
98 BitVector v(35);
99 v.Add(0);
100 BitVector w(35);
101 w.Add(33);
102 v.Union(w);
103 CHECK(v.Contains(0));
104 CHECK(v.Contains(33));
105 }
106
107 {
108 BitVector v(35);
109 v.Add(32);
110 v.Add(33);
111 BitVector w(35);
112 w.Add(33);
113 v.Intersect(w);
114 CHECK(!v.Contains(32));
115 CHECK(v.Contains(33));
116 BitVector r(35);
117 r.CopyFrom(v);
118 CHECK(!r.Contains(32));
119 CHECK(r.Contains(33));
120 }
121}