Commit e24e686f authored by Matija Obreza's avatar Matija Obreza
Browse files

Test case for issue #16

parent e0f0c9d5
......@@ -140,10 +140,10 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
return genusIdSpecies.keySet().parallelStream()
// convert each genus to Suggestion
.map(candidate -> new Suggestion<String>(candidate, similarityScore(genus, candidate)))
// keep decently scored suggestions
.filter(scored -> scored.getScore() >= .5)
// debug print
// .peek(InMemoryTaxonomyDatabase::print)
// keep decently scored suggestions
.filter(scored -> scored.getScore() > .5)
// convert to sequential stream
.sequential()
// debug print
......@@ -270,8 +270,8 @@ public class InMemoryTaxonomyDatabase implements TaxonomyDatabase {
LOG.trace("Species {} is a hybrid of {} and {}", species, speciesLeft, speciesRight);
}
List<Suggestion<String>> lefts = makeSuggestions(genus, speciesLeft).limit(maxSize).map(suggestion -> new Suggestion<>(suggestion.getSuggestion().getSpeciesName(), suggestion.getScore()))
.collect(Collectors.toList());
List<Suggestion<String>> lefts = makeSuggestions(genus, speciesLeft).limit(maxSize)
.map(suggestion -> new Suggestion<>(suggestion.getSuggestion().getSpeciesName(), suggestion.getScore())).collect(Collectors.toList());
List<Suggestion<String>> rights = makeSuggestions(genus, speciesRight).limit(maxSize)
.map(suggestion -> new Suggestion<>(suggestion.getSuggestion().getSpeciesName(), suggestion.getScore())).collect(Collectors.toList());
......
......@@ -119,6 +119,23 @@ public class TaxonomyCheckerTest extends DatabaseTest {
DATABASE.findSimilarGenus("Anizantha", 5);
}
/**
* Junepirus suggests Lepiurus;Neolepisorus, must recommend Juniperus
*/
@Test
public void testJunepirus() {
if (CHECKER == null) {
return;
}
assertThat("Junepirus is not a valid genus", DATABASE.containsGenus("Junepirus"), equalTo(false));
assertThat("Juniperus is a valid genus", DATABASE.containsGenus("Juniperus"), equalTo(true));
assertThat("Juniperus must be best suggestion", CHECKER.suggestGenus("Junepirus", 10), hasSize(greaterThan(0)));
assertThat("Juniperus must be suggested", CHECKER.suggestGenus("Junepirus", 10), hasItem("Juniperus"));
// FIXME Enable after implementing #16
// assertThat("Juniperus must be best suggestion", CHECKER.suggestGenus("Junepirus", 1), contains("Juniperus"));
}
/**
* Aragoptera Allagoptera;Gonoptera;Ragiopteris;Isoptera;Otoptera
*/
......@@ -133,7 +150,7 @@ public class TaxonomyCheckerTest extends DatabaseTest {
}
assertThat("Sorghum almum is a valid species", DATABASE.containsSpecies("Sorghum", "almum"), equalTo(true));
assertThat("Sorghum x almum is a valid species", DATABASE.containsSpecies("Sorghum", "x almum"), equalTo(true));
assertThat("Sorghum almum is only one species", DATABASE.findSpeciesRow("Sorghum", "almum", null), hasSize(1));
assertThat("Sorghum x almum is only one species", DATABASE.findSpeciesRow("Sorghum", "x almum", null), hasSize(1));
}
......@@ -153,7 +170,7 @@ public class TaxonomyCheckerTest extends DatabaseTest {
assertThat("Parodi is authority for species Sorghum almum", CHECKER.getSpeciesAuthority("Sorghum", "almum"), equalTo("Parodi"));
assertThat("Parodi is authority for species Sorghum x almum", CHECKER.getSpeciesAuthority("Sorghum", "x almum"), equalTo("Parodi"));
}
/**
* ETH013: GENUS=Sesbania and SPECIES=sesban x goetzei
*/
......@@ -164,10 +181,10 @@ public class TaxonomyCheckerTest extends DatabaseTest {
}
assertThat("Sesbania sesban is a valid species", DATABASE.containsSpecies("Sesbania", "sesban"), equalTo(true));
assertThat("Sesbania goetzei is a valid species", DATABASE.containsSpecies("Sesbania", "goetzei"), equalTo(true));
assertThat("Sesbania sesban x goetzei is a valid hybrid", DATABASE.containsSpecies("Sesbania", "sesban x goetzei"), equalTo(true));
}
/**
* ETH013: GENUS=Sesbania and SPECIES=grandiflora x goetzeii
*/
......@@ -182,18 +199,18 @@ public class TaxonomyCheckerTest extends DatabaseTest {
}
private void testMisspelledHybrid(String genus, String species1, String species2, String correctHybrid) {
// assertThat(genus + " " + species1 + " is a valid species", DATABASE.containsSpecies(genus, species1), equalTo(true));
// assertThat(genus + " " + species2 + " is not a valid species", DATABASE.containsSpecies(genus, species2), equalTo(false));
// assertThat("Must have suggestions for " + species1, CHECKER.suggestSpecies(genus, species1, 10), hasSize(greaterThan(0)));
// assertThat("Must have suggestions for " + species2, CHECKER.suggestSpecies(genus, species2, 10), hasSize(greaterThan(0)));
// assertThat(genus + " " + species1 + " is a valid species", DATABASE.containsSpecies(genus, species1), equalTo(true));
// assertThat(genus + " " + species2 + " is not a valid species", DATABASE.containsSpecies(genus, species2), equalTo(false));
// assertThat("Must have suggestions for " + species1, CHECKER.suggestSpecies(genus, species1, 10), hasSize(greaterThan(0)));
// assertThat("Must have suggestions for " + species2, CHECKER.suggestSpecies(genus, species2, 10), hasSize(greaterThan(0)));
String hybrid=species1 + " x " + species2;
// assertThat(genus + " " + hybrid + " is not a valid hybrid", DATABASE.containsSpecies(genus, hybrid), equalTo(false));
String hybrid = species1 + " x " + species2;
// assertThat(genus + " " + hybrid + " is not a valid hybrid", DATABASE.containsSpecies(genus, hybrid), equalTo(false));
assertThat("At least one suggestion must be made", CHECKER.suggestSpecies(genus, hybrid, 10), hasSize(greaterThan(0)));
assertThat("Suggestion must be " + correctHybrid, CHECKER.suggestSpecies(genus, hybrid, 1), contains(correctHybrid));
}
/**
* Acaena magellanica x tenera
*/
......@@ -203,9 +220,13 @@ public class TaxonomyCheckerTest extends DatabaseTest {
return;
}
assertThat("No suggestion must be made (no tenera suggestions)", CHECKER.suggestSpecies("Acaena", "magellanica x tenera", 10), hasSize(0));
testMisspelledHybrid("Acaena", "magellanic", "tenera", "magellanica x tenera");
testMisspelledHybrid("Acaena", "magellanicaa", "tenera", "magellanica x tenera");
}
/**
* Zygophyllon suggests too many options: Zygophyllum;Aphyllon;Phyllogonum;Zygophyllidium;Phyllophyton
*/
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment