Skip to content
Snippets Groups Projects
Commit 29b083ee authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

some small fixes and tests for BioTree.

parent b0a0ab13
No related branches found
No related tags found
No related merge requests found
UML.png

853 KiB | W: | H:

UML.png

853 KiB | W: | H:

UML.png
UML.png
UML.png
UML.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
......@@ -32,7 +32,7 @@ public class FileProcessor {
/**
* Sets a new path string
*/
public void setPath(String newPath) {
public static void setPath(String newPath) {
path = newPath;
}
......
package data;
import static org.junit.Assert.*;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import data.biotree.BioTree;
public class TestBioTree {
@Before
public static void main(String[] args) throws IOException {
BioTree.init();
BioTree.processRecord(125125);
BioTree.processRecord(125125);
BioTree.processRecord(125125);
BioTree.processRecord(125125);
BioTree.processRecord(125125);
BioTree.processRecord(125125);
BioTree.processRecord(125123);
BioTree.processRecord(125122);
BioTree.processRecord(125392);
BioTree.processRecord(125391);
BioTree.processRecord(600000000);
//System.out.println(nodes.size());
//System.out.println(nodes.get(123207));
//Iterable<Integer> keys = nodes.keys();
//for (Integer i: keys) {
// System.out.println(nodes.get(i));
//System.out.println(String.format("%-26s %s", nodes.get(i).getName(), nodes.get(i).getTaxonType()));
//}
BioTree.printTree();
}
}
......@@ -23,7 +23,7 @@ import search.RedBlackTree;
*/
public class BioTree implements Serializable {
/**
*
* Serializable version ID. Requires by Serializable interface.
*/
private static final long serialVersionUID = 4291273291916906661L;
/**
......@@ -232,8 +232,14 @@ public class BioTree implements Serializable {
* @throws ParseException
* @throws IOException
*/
public static TaxonNode getTaxonRecord(String scientificName) throws IOException, ParseException {
return idNodes.get(nameToTaxonId(scientificName));
public static TaxonNode getTaxonRecord(String scientificName) {
try {
Integer taxonId = nameToTaxonId(scientificName);
if (taxonId == null) return null;
return idNodes.get(taxonId);
} catch (IOException | ParseException e0) {
return null;
}
}
/**
......
package data.biotree;
import static org.junit.Assert.*;
import org.json.simple.parser.ParseException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import data.FileProcessor;
import search.trawl.BasicSearch;
/**
* Testing was performed on a small dataset for which we know the correct numbers of data for each
* taxon. Takes a while to process the dataset since most of the species in the set are unique and
* thus require API calls.
* @author TrawlStars, Inc.
*
*/
public class TestBio {
/**
* Loads the small dataset into memory using the FileProcessor.
* @throws Exception Cannot find dataset given.
*/
@BeforeClass
public static void setUp() throws Exception {
//load small test dataset
BioTree.init();
FileProcessor.setPath("smalldata.csv");
FileProcessor.initProcessing();
}
@Test
public void testAnuraExists() throws ParseException {
assert(BioTree.getTaxonRecord("Anura") != null);
}
@Test
public void testGetTaxonNode() {
//test that Esox is in dataset
assert(BioTree.getTaxonRecord("Esox lucius") != null);
}
@Test
public void testGetTaxonNodeFails() {
//test that Esox is in dataset
assert(BioTree.getTaxonRecord("Mythical Creature") == null);
}
@Test
public void testGetCount() {
//test count is correct
assert(BioTree.getTaxonRecord("Esox lucius").getCount() == 4);
}
@Test
public void testGetName() {
//test name correct
assert(BioTree.getTaxonRecord("Esox lucius").getName().equals("Esox lucius"));
}
@Test
public void testGetParent() {
//test that the correct parent has been stored in the dataset
assert(BioTree.getTaxonRecord("Esox lucius").getParent().getTaxonId() == 154208);
}
@Test
public void testGetChildren() {
//test that the correct parent has been stored in the dataset
for (TaxonNode tx: BioTree.getTaxonRecord("Esox").getChildren())
assert(tx.getName().equals("Esox lucius") || tx.getName().equals("Esox masquinongy"));
}
}
package data.biotree;
import static org.junit.Assert.*;
import java.io.IOException;
import org.json.simple.parser.ParseException;
import org.junit.Before;
import org.junit.Test;
import data.FileProcessor;
public class TestBioTree {
@Before
public static void main(String[] args) throws IOException {
// BioTree.init();
// BioTree.processRecord(125125);
// BioTree.processRecord(125125);
// BioTree.processRecord(125125);
// BioTree.processRecord(125125);
// BioTree.processRecord(125125);
// BioTree.processRecord(125125);
// BioTree.processRecord(125123);
// BioTree.processRecord(125122);
// BioTree.processRecord(125392);
// BioTree.processRecord(125391);
// BioTree.processRecord(600000000);
// //System.out.println(nodes.size());
// //System.out.println(nodes.get(123207));
// //Iterable<Integer> keys = nodes.keys();
// //for (Integer i: keys) {
// // System.out.println(nodes.get(i));
// //System.out.println(String.format("%-26s %s", nodes.get(i).getName(), nodes.get(i).getTaxonType()));
// //}
// BioTree.printTree();
}
@Test
public void testSmallDataset() throws NumberFormatException, ParseException, IOException {
BioTree.init();
//FileProcessor.setPath("smalldata.csv");
FileProcessor.initProcessing();
assert(BioTree.getTaxonRecord("Anura") != null);
assert(false);
}
}
......@@ -15,7 +15,9 @@ import search.trawl.BasicSearchResult;
/**
* The model of the TrawlExpert codebase. Gives hooks to views such as the server
* and the command-line interface.
* and the command-line interface. Attempts to load serialized data from the disc,
* but if that fails it will regenerate the BioTree and Record kd-tree from the
* original dataset, then save the serialized data when it's done.
* @author Christopher W. Schankula
*
*/
......@@ -77,7 +79,7 @@ public class TrawlExpert {
public TaxonNode getTaxonRecord(String scientificName) {
try {
return BioTree.getTaxonRecord(scientificName);
} catch (IOException | ParseException e) {
} catch (ParseException e) {
}
return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment