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

add first minimal working BioTree and a few tests for it

parent f31ab094
No related branches found
No related tags found
No related merge requests found
......@@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
package biotree;
public class BioTree {
private static Species[] species;
private static int n;
/**
* Initialize species abstract object
*/
public static void init() {
species = new Species[500];
n = 0;
}
/**
* TODO: Implement
*
* @param fn
* Filename to read from
*/
public static void init(String fn) {
}
/**
* TODO: Implement
*
* @param fn
* Filename to write to
*/
public static void write(String fn) {
}
/**
* Add a new species to the module
*
* @param s
* New Species to add.
* @return speciesid of new species entry
*/
public static int addSpecies(Species s) {
species[n++] = s;
return n;
}
/**
* Update an existing species object.
*
* @param i
* The index of the species to update.
* @param s
* The new Species object to overwrite the old one with.
*/
public static void updateSpecies(int i, Species s) {
species[i] = s;
}
/**
* Get the species at a given index (speciesid).
*
* @param i
* The speciesid (index) of the species.
* @return The Species object.
*/
public static Species getSpecies(int i) {
return species[i];
}
/**
* Search for a species by name.
*
* @param s
* The name of the species.
* @return The speciesid of the species or -1 if it is not found.
*/
public static int findSpecies(String s) {
for (int i = 0; i < n; i++)
if (species[i].getSpecies() == s)
return i;
return -1;
}
/**
* TODO: Implement
*
* @param s
* The name of the genus.
* @return Array of speciesid belonging to the genus.
*/
public static int[] findGenus(String s) {
int[] dummy = { 1, 2, 3 };
return dummy;
}
/**
* TODO: Implement
*
* @param s
* The name of the family.
* @return Array of speciesid belonging to the family.
*/
public static int[] findFamily(String s) {
int[] dummy = { 1, 2, 3 };
return dummy;
}
/**
* TODO: Implement
*
* @param s
* The name of the order.
* @return Array of speciesid belonging to the order.
*/
public static int[] findOrder(String s) {
int[] dummy = { 1, 2, 3 };
return dummy;
}
}
package biotree;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class TestBioTree {
@Before
public void setUp() throws Exception {
BioTree.init();
Species s0 = new Species("Actinopterygii","Perciformes","Moronidae","Morone","Morone chrysops");
Species s1 = new Species("Actinopterygii","Perciformes","Percidae","Perca","Perca flavescens");
BioTree.addSpecies(s0);
BioTree.addSpecies(s1);
}
@Test
public void testFindSpecies() {
assert BioTree.findSpecies("Morone chrysops") == 0;
assert BioTree.findSpecies("Perca flavescens") == 1;
}
@Test
public void testGetSpecies() {
assert BioTree.getSpecies(0).getSpecies() == "Morone chrysops";
assert BioTree.getSpecies(1).getSpecies() == "Perca flavescens";
}
}
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