-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
220 additions
and
40 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
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
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
56 changes: 56 additions & 0 deletions
56
src/test/java/com/nucleodb/library/database/index/TreeIndexTest.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,56 @@ | ||
package com.nucleodb.library.database.index; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.nucleodb.library.database.index.helpers.TestClass; | ||
import com.nucleodb.library.database.tables.table.DataEntry; | ||
import com.nucleodb.library.database.utils.Serializer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TreeIndexTest{ | ||
|
||
@Test | ||
void add() throws JsonProcessingException { | ||
TreeIndex index = new TreeIndex<TestClass>("name"); | ||
index.add(new DataEntry(new TestClass("taco test"))); | ||
assertEquals(1, index.contains("taco").size()); | ||
} | ||
|
||
@Test | ||
void delete() throws JsonProcessingException { | ||
DataEntry tacoTest = new DataEntry(new TestClass("taco test")); | ||
TreeIndex index = new TreeIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
assertEquals(1, index.contains("taco").size()); | ||
assertEquals(1, index.getIndex().size()); | ||
assertEquals(1, index.getReverseMap().size()); | ||
index.delete(tacoTest); | ||
assertEquals(0, index.contains("taco").size()); | ||
assertEquals(0, index.getIndex().size()); | ||
assertEquals(0, index.getReverseMap().size()); | ||
} | ||
|
||
@Test | ||
void modify() throws JsonProcessingException { | ||
DataEntry<TestClass> tacoTest = new DataEntry(new TestClass("taco test")); | ||
TreeIndex index = new TreeIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
assertEquals(1, index.contains("taco").size()); | ||
assertEquals(1, index.getIndex().size()); | ||
assertEquals(1, index.getReverseMap().size()); | ||
tacoTest.getData().setName("just test"); | ||
index.modify(tacoTest); | ||
assertEquals(1, index.contains("just").size()); | ||
assertEquals(1, index.getIndex().size()); | ||
assertEquals(1, index.getReverseMap().size()); | ||
} | ||
|
||
@Test | ||
void get() { | ||
} | ||
|
||
@Test | ||
void contains() { | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/test/java/com/nucleodb/library/database/index/TrieIndexTest.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,101 @@ | ||
package com.nucleodb.library.database.index; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.nucleodb.library.database.index.helpers.TestClass; | ||
import com.nucleodb.library.database.index.trie.Node; | ||
import com.nucleodb.library.database.tables.table.DataEntry; | ||
import com.nucleodb.library.database.utils.Serializer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Stack; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
class TrieIndexTest{ | ||
|
||
@Test | ||
void add() throws JsonProcessingException { | ||
TrieIndex index = new TrieIndex<TestClass>("name"); | ||
index.add(new DataEntry(new TestClass("taco test"))); | ||
assertEquals(1, index.search("taco").size()); | ||
} | ||
|
||
@Test | ||
void modify() throws JsonProcessingException { | ||
DataEntry<TestClass> tacoTest = new DataEntry(new TestClass("taco test")); | ||
TrieIndex index = new TrieIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
tacoTest.getData().setName("burrito"); | ||
index.modify(tacoTest); | ||
assertEquals(0, index.search("taco").size()); | ||
Stack<Node> nodes = new Stack<Node>(); | ||
nodes.add(index.root); | ||
int x = 0; | ||
while(!nodes.isEmpty()){ | ||
Node n = nodes.pop(); | ||
nodes.addAll(n.getNodes().values()); | ||
x++; | ||
} | ||
assertEquals(8, x); // characters + 1(root) | ||
assertEquals(1, index.search("burrito").size()); | ||
} | ||
|
||
@Test | ||
void get() throws JsonProcessingException { | ||
String name = "taco test"; | ||
DataEntry<TestClass> tacoTest = new DataEntry(new TestClass(name)); | ||
TrieIndex index = new TrieIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
assertEquals(1, index.get(name).size()); | ||
Stack<Node> nodes = new Stack<>(); | ||
nodes.add(index.root); | ||
int x = 0; | ||
while(!nodes.isEmpty()){ | ||
Node n = nodes.pop(); | ||
nodes.addAll(n.getNodes().values()); | ||
x++; | ||
} | ||
assertEquals(name.length()+1, x); // characters + 1(root) | ||
} | ||
|
||
@Test | ||
void contains() throws JsonProcessingException { | ||
String name = "vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget arcu dictum varius duis at consectetur lorem donec massa sapien"; | ||
DataEntry<TestClass> tacoTest = new DataEntry(new TestClass(name)); | ||
TrieIndex index = new TrieIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
assertEquals(1, index.search("rho").size()); | ||
Stack<Node> nodes = new Stack<>(); | ||
nodes.add(index.root); | ||
int x = 0; | ||
while(!nodes.isEmpty()){ | ||
Node n = nodes.pop(); | ||
nodes.addAll(n.getNodes().values()); | ||
x++; | ||
} | ||
assertEquals(name.length()+1, x); // characters + 1(root) | ||
assertEquals(1, index.entries.size()); | ||
} | ||
|
||
@Test | ||
void delete() throws JsonProcessingException { | ||
String name = "taco test"; | ||
DataEntry<TestClass> tacoTest = new DataEntry(new TestClass(name)); | ||
TrieIndex index = new TrieIndex<TestClass>("name"); | ||
index.add(tacoTest); | ||
assertEquals(1, index.get(name).size()); | ||
index.delete(tacoTest); | ||
Stack<Node> nodes = new Stack<>(); | ||
nodes.add(index.root); | ||
int x = 0; | ||
while(!nodes.isEmpty()){ | ||
Node n = nodes.pop(); | ||
nodes.addAll(n.getNodes().values()); | ||
x++; | ||
} | ||
assertEquals(1, x); // characters + 1(root) | ||
assertEquals(0, index.entries.size()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/com/nucleodb/library/database/index/helpers/TestClass.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,20 @@ | ||
package com.nucleodb.library.database.index.helpers; | ||
|
||
public class TestClass { | ||
String name = "test"; | ||
|
||
public TestClass() { | ||
} | ||
|
||
public TestClass(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |