testing the big test: there and back again!

This commit is contained in:
Vincent Batts 2012-11-02 10:56:48 -04:00
parent b36fddf91d
commit c9081b41b5

View file

@ -2,6 +2,7 @@ package com.redhat.trie;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.InputStream; import java.io.InputStream;
@ -9,6 +10,7 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test; import org.junit.Test;
@ -23,14 +25,86 @@ public class TestPathTree {
@Test @Test
public void testNew1() { public void testNew1() {
PathTree pt = new PathTree(); PathTree pt = new PathTree();
List<String> contents = loadContents("contents.list");
try {
pt = new PathTree(contents);
} catch (PayloadException ex) {
fail(ex.toString());
}
assertNotNull(pt); assertNotNull(pt);
} }
@Test
public void testNew2() {
PathTree pt = new PathTree();
List<String> contents = loadContents("contents.list");
try {
pt.setContentSets(contents);
} catch (PayloadException ex) {
fail(ex.toString());
}
assertNotNull(pt);
}
@Test
public void testThereAndBackAgainCS() {
PathTree pt0 = new PathTree();
PathTree pt1;
List<String> contents0 = loadContents("contents.list");
List<String> contents1;
byte[] bytes;
try {
pt0.setContentSets(contents0);
} catch (PayloadException ex) {
fail(ex.toString());
}
bytes = pt0.getPayload();
assertNotNull(bytes);
printByteArray(bytes);
pt1 = new PathTree(bytes);
contents1 = pt1.toList();
Collections.sort(contents0);
Collections.sort(contents1);
for (String thisS : contents0) {
if (! contents1.contains(thisS)) {
System.out.println(thisS);
}
}
//System.out.println(contents0.size());
//System.out.println(contents1.size());
assertEquals(contents0.size(), contents1.size());
}
// Helpers
//
private void printByteArray(byte[] bytes) {
int width = 30;
int counter = 0;
for (byte b : bytes) {
System.out.format("%02X ", b);
counter++;
if (counter > width) {
counter = 0;
System.out.println();
}
}
System.out.println();
}
private InputStream resStream(String filename) { private InputStream resStream(String filename) {
return getClass().getClassLoader().getResourceAsStream(filename); return getClass().getClassLoader().getResourceAsStream(filename);
} }
private List<String> loadContents(String filename) throws IOException { private List<String> loadContents(String filename) {
String content; String content;
List<String> contentList = new ArrayList<String>(); List<String> contentList = new ArrayList<String>();
InputStream in = resStream(filename); InputStream in = resStream(filename);
@ -41,7 +115,7 @@ public class TestPathTree {
contentList.add(content); contentList.add(content);
} }
} catch (IOException ex) { } catch (IOException ex) {
throw ex; fail();
} }
return contentList; return contentList;
} }