-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a88c5de
commit 3db3c90
Showing
4 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
trie4j/src/test/java/org/trie4j/bv/LongsRank0OnlySuccinctBitVectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Takao Nakaguchi | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.trie4j.bv; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class LongsRank0OnlySuccinctBitVectorTest | ||
extends AbstractSuccinctBitVectorTest { | ||
protected SuccinctBitVector create() { | ||
return new LongsRank0OnlySuccinctBitVector(1); | ||
} | ||
protected SuccinctBitVector create(int initialCapacity) { | ||
return new LongsRank0OnlySuccinctBitVector(initialCapacity); | ||
} | ||
protected SuccinctBitVector create(byte[] bytes, int bitsSize) { | ||
return new LongsRank0OnlySuccinctBitVector(bytes, bitsSize); | ||
} | ||
|
||
@Test | ||
public void test() throws Exception{ | ||
SuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector(1); | ||
bv.append0(); | ||
bv.append1(); | ||
Assert.assertEquals(1, bv.rank0(0)); | ||
Assert.assertEquals(1, bv.rank0(1)); | ||
Assert.assertEquals(2, bv.rank0(2)); | ||
Assert.assertEquals(3, bv.rank0(3)); | ||
Assert.assertEquals(4, bv.rank0(4)); | ||
Assert.assertEquals(5, bv.rank0(5)); | ||
Assert.assertEquals(6, bv.rank0(6)); | ||
Assert.assertEquals(7, bv.rank0(7)); | ||
try{ | ||
bv.rank0(64); | ||
Assert.fail(); | ||
} catch(ArrayIndexOutOfBoundsException e){ | ||
} | ||
} | ||
|
||
@Test | ||
public void test2() throws Exception{ | ||
SuccinctBitVector bv = new LongsRank0OnlySuccinctBitVector( | ||
new byte[]{0x2d, 0x3f}, 16); | ||
Assert.assertEquals(1, bv.rank0(0)); | ||
Assert.assertEquals(2, bv.rank0(1)); | ||
Assert.assertEquals(2, bv.rank0(2)); | ||
Assert.assertEquals(3, bv.rank0(3)); | ||
Assert.assertEquals(3, bv.rank0(4)); | ||
Assert.assertEquals(3, bv.rank0(5)); | ||
Assert.assertEquals(4, bv.rank0(6)); | ||
Assert.assertEquals(4, bv.rank0(7)); | ||
Assert.assertEquals(5, bv.rank0(8)); | ||
Assert.assertEquals(6, bv.rank0(9)); | ||
Assert.assertEquals(6, bv.rank0(10)); | ||
Assert.assertEquals(6, bv.rank0(11)); | ||
Assert.assertEquals(6, bv.rank0(12)); | ||
Assert.assertEquals(6, bv.rank0(13)); | ||
Assert.assertEquals(6, bv.rank0(14)); | ||
Assert.assertEquals(6, bv.rank0(15)); | ||
try{ | ||
bv.rank0(64); | ||
Assert.fail(); | ||
} catch(ArrayIndexOutOfBoundsException e){ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters