Skip to content

Commit

Permalink
Added a _different test in addition to the _same test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed May 8, 2024
1 parent a16f16e commit 2f7ac95
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 41 deletions.
72 changes: 72 additions & 0 deletions test/examples/correct/normalization/brochu_2003_normalization.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,78 @@
},
"label": "Caiman crocodilus"
},
{
"@type": "http://rs.tdwg.org/ontology/voc/TaxonConcept#TaxonConcept",
"hasName": {
"@type": "http://rs.tdwg.org/ontology/voc/TaxonName#TaxonName",
"nomenclaturalCode": "http://rs.tdwg.org/ontology/voc/TaxonName#ICZN",
"label": "Alligator mississippiensis",
"nameComplete": "Alligator mississippiensis"
},
"label": "Alligator mississippiensis"
}
],
"externalSpecifiers": []
},
{
"@id": "#Alligatoridae2_different",
"label": "Alligatoridae",
"scientificNameAuthorship": {
"bibliographicCitation": "(Cuvier 1807)"
},
"phylorefType": "phyloref:PhyloreferenceUsingMinimumClade",
"definition": "Alligatoridae (Cuvier 1807).\n\nLast common ancestor of Alligator mississippiensis and Caiman crocodilus and all of its descendents.",
"definitionSource": {
"type": "article",
"title": "Phylogenetic approaches toward crocodylian history",
"authors": [
{
"name": "Christopher A. Brochu",
"alternate": [
"Brochu, Christopher A."
],
"firstname": "Christopher",
"middlename": "A.",
"lastname": "Brochu"
}
],
"year": 2003,
"figure": "1",
"identifier": [
{
"type": "doi",
"id": "10.1146/annurev.earth.31.100901.141308"
}
],
"link": [
{
"url": "https://www.annualreviews.org/doi/10.1146/annurev.earth.31.100901.141308"
}
],
"journal": {
"name": "Annual Review of Earth and Planetary Sciences",
"volume": "31",
"pages": "357--397",
"identifier": [
{
"type": "eISSN",
"id": "1545-4495"
}
]
}
},
"internalSpecifiers": [
{
"@type": "http://rs.tdwg.org/ontology/voc/TaxonConcept#TaxonConcept",
"hasName": {
"@type": "http://rs.tdwg.org/ontology/voc/TaxonName#TaxonName",
"label": "Caiman crocodilus",
"nameComplete": "Caiman crocodilus",
"genusPart": "Caiman",
"specificEpithet": "crocodilus"
},
"label": "Caiman crocodilus"
},
{
"@type": "http://rs.tdwg.org/ontology/voc/TaxonConcept#TaxonConcept",
"hasName": {
Expand Down
88 changes: 47 additions & 41 deletions test/normalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,53 +68,59 @@ describe('Phyloref and phylogeny normalization', function () {
expect(samePhylorefs).to.not.be.empty;
});

// No two phyloreferences in a normalization file should be deeply identical to each
// other, otherwise the test will be pointless.
phylorefs.forEach((phyloref1) => {
phylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(removeId(phyloref1))
.to
.not
.deep
.equal(removeId(phyloref2),
'No two phyloreferences in a single normalization file should be identical.');
it('should not have any duplicate phylorefs (which would be pointless)', function () {
// No two phyloreferences in a normalization file should be deeply identical to each
// other, otherwise the test will be pointless.
phylorefs.forEach((phyloref1) => {
phylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(removeId(phyloref1))
.to
.not
.deep
.equal(removeId(phyloref2),
'No two phyloreferences in a single normalization file should be identical.');
});
});
});

// Every pair of `_same` phyloreferences should be different.
samePhylorefs.forEach((phyloref1) => {
samePhylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(
removeId(phyx.PhylorefWrapper.normalize(phyloref1))
)
.to
.deep
.equal(
removeId(phyx.PhylorefWrapper.normalize(phyloref2)),
`Expected phyloref ${phyloref1['@id']} to deeply equal ${phyloref2['@id']} `
+ 'after normalization'
);
it('should have pairs of `_same` phylorefs that are different, but are identical after normalization', function () {
// Every pair of `_same` phyloreferences should be different.
samePhylorefs.forEach((phyloref1) => {
samePhylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(
removeId(phyx.PhylorefWrapper.normalize(phyloref1))
)
.to
.deep
.equal(
removeId(phyx.PhylorefWrapper.normalize(phyloref2)),
`Expected phyloref ${phyloref1['@id']} to deeply equal ${phyloref2['@id']} `
+ 'after normalization'
);
});
});
});

// Every pair of `_different` phyloreferences should be different from every `_same`
// phyloreference, even after normalization.
differentPhylorefs.forEach((phyloref1) => {
samePhylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(
removeId(phyx.PhylorefWrapper.normalize(phyloref1))
)
.to
.not
.deep
.equal(
removeId(phyx.PhylorefWrapper.normalize(phyloref2)),
`Expected phyloref ${phyloref1['@id']} to not deeply equal ${phyloref2['@id']} `
+ 'after normalization'
);
it('should have pairs of `_different` phylorefs that are different before and after normalization', function () {
// Every pair of `_different` phyloreferences should be different from every `_same`
// phyloreference, even after normalization.
differentPhylorefs.forEach((phyloref1) => {
samePhylorefs.forEach((phyloref2) => {
if (phyloref1 === phyloref2) return;
expect(
removeId(phyx.PhylorefWrapper.normalize(phyloref1))
)
.to
.not
.deep
.equal(
removeId(phyx.PhylorefWrapper.normalize(phyloref2)),
`Expected phyloref ${phyloref1['@id']} to not deeply equal ${phyloref2['@id']} `
+ 'after normalization'
);
});
});
});
});
Expand Down

0 comments on commit 2f7ac95

Please sign in to comment.