diff options
Diffstat (limited to 'src/test/java/io/trygvis/btree/HeapTest.java')
-rw-r--r-- | src/test/java/io/trygvis/btree/HeapTest.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/java/io/trygvis/btree/HeapTest.java b/src/test/java/io/trygvis/btree/HeapTest.java index 1d724f4..48a1463 100644 --- a/src/test/java/io/trygvis/btree/HeapTest.java +++ b/src/test/java/io/trygvis/btree/HeapTest.java @@ -4,6 +4,8 @@ import org.junit.Test; import java.io.File; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import static io.trygvis.btree.HeapTest.Person.randomPerson; @@ -14,6 +16,8 @@ public class HeapTest { @Test public void testHeap() throws Exception { + List<Person> persons = new ArrayList<Person>(); + File f = new File("target/heapTest"); HeapFile file = new HeapFile(128, deleteFile(f)); @@ -23,6 +27,7 @@ public class HeapTest { int pageNo = 0; for (int i = 0; i < 10; i++) { Person p = randomPerson(); + persons.add(p); byte[] bytes = p.toBytes(); @@ -47,13 +52,15 @@ public class HeapTest { System.out.println("file.pageCount() = " + file.pageCount()); + int counter = 0; for (int i = 0; i < file.pageCount(); i++) { System.out.println("page #" + i); page = file.loadPage(i); - for (ByteBuffer buffer : page.bufferIterator()) { + for (ByteBuffer buffer : page.items()) { Person p = Person.fromBytes(buffer); System.out.println("p = " + p); + assertEquals(persons.get(counter++), p); } } } @@ -91,6 +98,23 @@ public class HeapTest { '}'; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Person)) return false; + + Person person = (Person) o; + + return age == person.age && name.equals(person.name); + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + age; + return result; + } + private final static Random r = new Random(0); private final static String[] names = new String[]{ "Lukas", "Emil", "Mathias", "Jonas", "Aleksander", "William", "Oskar", "Magnus", "Markus", "Oliver", |