Skip to content

Commit

Permalink
add read/write test for TailLOUDSTrie.
Browse files Browse the repository at this point in the history
  • Loading branch information
takawitter committed Oct 9, 2023
1 parent c3fbf8e commit 1732810
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions trie4j/src/test/java/org/trie4j/io/RWTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.trie4j.io;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.junit.Assert;
import org.junit.Test;
import org.trie4j.Trie;
import org.trie4j.louds.TailLOUDSTrie;
import org.trie4j.louds.bvtree.LOUDSPPBvTree;
import org.trie4j.patricia.PatriciaTrie;
import org.trie4j.tail.SuffixTrieDenseTailArrayBuilder;


public class RWTest {
@Test
public void test() throws Throwable{
Trie ot = new PatriciaTrie();
ot.insert("hello");
ot.insert("hell");
ot.insert("world");
Trie t2 = new TailLOUDSTrie(ot, new LOUDSPPBvTree(ot.nodeSize()),
new SuffixTrieDenseTailArrayBuilder());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new TrieWriter(baos).write(t2);
Trie t3 = new TrieReader(new ByteArrayInputStream(baos.toByteArray()))
.read();
Assert.assertEquals(t2.getClass(), t3.getClass());
Assert.assertEquals(t2.size(), t3.size());
Assert.assertEquals(t2.nodeSize(), t3.nodeSize());
for(String w : t2.predictiveSearch("")) {
Assert.assertTrue(t3.contains(w));
}

}
}

0 comments on commit 1732810

Please sign in to comment.