TestTermVectorsReaderpublic class TestTermVectorsReader extends TestCase
Fields Summary |
---|
private TermVectorsWriter | writer | private String[] | testFields | private String[] | testTerms | private RAMDirectory | dir | private String | seg | private FieldInfos | fieldInfos |
Constructors Summary |
---|
public TestTermVectorsReader(String s)
super(s);
|
Methods Summary |
---|
protected void | setUp()
for (int i = 0; i < testFields.length; i++) {
fieldInfos.add(testFields[i], true, true);
}
try {
Arrays.sort(testTerms);
for (int j = 0; j < 5; j++) {
writer = new TermVectorsWriter(dir, seg, fieldInfos);
writer.openDocument();
for (int k = 0; k < testFields.length; k++) {
writer.openField(testFields[k]);
for (int i = 0; i < testTerms.length; i++) {
writer.addTerm(testTerms[i], i);
}
writer.closeField();
}
writer.closeDocument();
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
assertTrue(false);
}
| protected void | tearDown()
| public void | test()
//Check to see the files were created properly in setup
assertTrue(writer.isDocumentOpen() == false);
assertTrue(dir.fileExists(seg + TermVectorsWriter.TVD_EXTENSION));
assertTrue(dir.fileExists(seg + TermVectorsWriter.TVX_EXTENSION));
| public void | testBadParams()Make sure exceptions and bad params are handled appropriately
try {
TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
assertTrue(reader != null);
//Bad document number, good field number
TermFreqVector vector = reader.get(50, testFields[0]);
assertTrue(vector == null);
} catch (Exception e) {
assertTrue(false);
}
try {
TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
assertTrue(reader != null);
//good document number, bad field number
TermFreqVector vector = reader.get(0, "f50");
assertTrue(vector == null);
} catch (Exception e) {
assertTrue(false);
}
| public void | testReader()
try {
TermVectorsReader reader = new TermVectorsReader(dir, seg, fieldInfos);
assertTrue(reader != null);
TermFreqVector vector = reader.get(0, testFields[0]);
assertTrue(vector != null);
String [] terms = vector.getTerms();
assertTrue(terms != null);
assertTrue(terms.length == testTerms.length);
for (int i = 0; i < terms.length; i++) {
String term = terms[i];
//System.out.println("Term: " + term);
assertTrue(term.equals(testTerms[i]));
}
} catch (IOException e) {
e.printStackTrace();
assertTrue(false);
}
|
|