Skip to content

Commit

Permalink
Replaced index-based lookups w/ name-based lookups
Browse files Browse the repository at this point in the history
Using index-based lookups relies on JPhyloRef returning phylorefs in a
particular order, which it doesn't.
  • Loading branch information
gaurav committed Jan 30, 2019
1 parent a7c0c52 commit 3a51a6d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/test_phyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ describe('Test PHYX files in repository', function() {
assert.isAbove(json.phylorefs.length, 0);
});

// Create a dictionary of phyloreferences by label.
const wrappedPhylorefsByLabel = {};
json.phylorefs.forEach(phyloref => {
const wrapped = new phyx.PhylorefWrapper(phyloref);
wrappedPhylorefsByLabel[wrapped.label] = wrapped;
});

// Test the produced JSON-LD using JPhyloRef.
var args = [
'-jar', 'jphyloref/jphyloref.jar',
Expand Down Expand Up @@ -123,7 +130,16 @@ describe('Test PHYX files in repository', function() {
});
});
tapParser.on('assert', result => {
const phyloref = new phyx.PhylorefWrapper(json.phylorefs[result.id - 1]);
const matches = result.name.match(/^Phyloreference '(.*)'$/);
if(matches === null) {
throw new RuntimeException(`Invalid test name: '${result.name}'`);
}

const phyloref = wrappedPhylorefsByLabel[matches[1]];
if(!phyloref) {
throw new RuntimeException(`Phyloreference '${matches[1]}' was tested but is not present in the input PHYX file`);
}

const countInternal = phyloref.phyloref.internalSpecifiers.length;
const countExternal = phyloref.phyloref.externalSpecifiers.length;
describe(`Phyloreference ${phyloref.label} (${countInternal} internal specifiers, ${countExternal} external specifiers)`, function () {
Expand Down

0 comments on commit 3a51a6d

Please sign in to comment.