1 /*--------------------------------------------------------------------------
\r
2 * Copyright 2008 Taro L. Saito
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
15 *--------------------------------------------------------------------------*/
\r
16 //--------------------------------------
\r
19 // BitVectorTest.java
\r
20 // Since: 2008/11/08 10:01:51
\r
24 //--------------------------------------
\r
25 package org.xerial.util;
\r
27 import static org.junit.Assert.assertEquals;
\r
28 import static org.junit.Assert.assertFalse;
\r
29 import static org.junit.Assert.assertNotSame;
\r
30 import static org.junit.Assert.assertTrue;
\r
32 import org.junit.Test;
\r
33 import org.xerial.util.log.Logger;
\r
35 public class BitVectorTest
\r
37 private static Logger _logger = Logger.getLogger(BitVectorTest.class);
\r
40 public void testBitVector()
\r
42 BitVector bv = new BitVector();
\r
44 assertEquals("01", bv.toString());
\r
45 assertEquals(2, bv.size());
\r
48 assertEquals("010001", bv.toString());
\r
49 assertEquals(6, bv.size());
\r
54 public void testSetAndGet()
\r
56 BitVector bv = new BitVector();
\r
57 for (int i = 0; i < 10000; i++)
\r
59 assertFalse(bv.get(i));
\r
61 assertTrue(bv.get(i));
\r
67 public void testOnOff()
\r
69 BitVector bv = new BitVector();
\r
70 for (int i = 0; i < 10000; i++)
\r
72 assertFalse(bv.get(i));
\r
74 assertTrue(bv.get(i));
\r
77 int[] pos = { 1, 34, 5093, 443, 4 };
\r
78 for (int offIndex : pos)
\r
81 assertFalse(bv.get(offIndex));
\r
89 public void testEqualsObject()
\r
91 BitVector bv = new BitVector();
\r
92 BitVector bv2 = new BitVector();
\r
93 int[] pos = { 1, 34, 43, 13, 4 };
\r
94 for(int index : pos)
\r
98 assertTrue(bv.get(index));
\r
99 assertTrue(bv2.get(index));
\r
102 assertEquals(bv, bv2);
\r
103 assertEquals(bv.hashCode(), bv2.hashCode());
\r
104 assertEquals(bv.size(), bv2.size());
\r
107 assertNotSame(bv, bv2);
\r
108 assertNotSame(bv.size(), bv2.size());
\r
112 public void testNewInstance()
\r
114 BitVector bv = new BitVector();
\r
115 int[] pos = { 1, 34, 43, 13, 4 };
\r
116 for (int index : pos)
\r
119 assertTrue(bv.get(index));
\r
122 BitVector bv2 = BitVector.newInstance(bv);
\r
123 assertEquals(bv, bv2);
\r
124 assertEquals(bv.hashCode(), bv2.hashCode());
\r
125 assertEquals(bv.size(), bv2.size());
\r
128 assertNotSame(bv, bv2);
\r
129 assertNotSame(bv.size(), bv2.size());
\r