blob: 43d950d86069af33f15dea8409c7529352c2c0ea [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Steve Block6ded16b2010-05-10 14:33:55 +01002// 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
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030#include "src/v8.h"
Steve Block6ded16b2010-05-10 14:33:55 +010031
Ben Murdochb8a8cc12014-11-26 15:28:44 +000032#include "src/data-flow.h"
33#include "test/cctest/cctest.h"
Steve Block6ded16b2010-05-10 14:33:55 +010034
35using namespace v8::internal;
36
37TEST(BitVector) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038 Zone zone(CcTest::i_isolate());
Steve Block6ded16b2010-05-10 14:33:55 +010039 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040 BitVector v(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010041 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);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047 BitVector w(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010048 w.Add(1);
49 v.Intersect(w);
50 CHECK(!v.Contains(0));
51 CHECK(v.Contains(1));
52 }
53
54 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 BitVector v(64, &zone);
Ben Murdochb0fe1622011-05-05 13:52:32 +010056 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 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073 BitVector v(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010074 v.Add(0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 BitVector w(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010076 w.Add(1);
77 v.Union(w);
78 CHECK(v.Contains(0));
79 CHECK(v.Contains(1));
80 }
81
82 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000083 BitVector v(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010084 v.Add(0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085 BitVector w(15, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010086 w = v;
87 CHECK(w.Contains(0));
88 w.Add(1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089 BitVector u(w, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010090 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 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098 BitVector v(35, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +010099 v.Add(0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100 BitVector w(35, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +0100101 w.Add(33);
102 v.Union(w);
103 CHECK(v.Contains(0));
104 CHECK(v.Contains(33));
105 }
106
107 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000108 BitVector v(35, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +0100109 v.Add(32);
110 v.Add(33);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111 BitVector w(35, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +0100112 w.Add(33);
113 v.Intersect(w);
114 CHECK(!v.Contains(32));
115 CHECK(v.Contains(33));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000116 BitVector r(35, &zone);
Steve Block6ded16b2010-05-10 14:33:55 +0100117 r.CopyFrom(v);
118 CHECK(!r.Contains(32));
119 CHECK(r.Contains(33));
120 }
121}