From ccdedebcb5a548d66ff3bec9067db147b5fb1be7 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:19:35 -0400 Subject: [PATCH] test: fix tests --- __test__/integration/biolink.test.ts | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 __test__/integration/biolink.test.ts diff --git a/__test__/integration/biolink.test.ts b/__test__/integration/biolink.test.ts new file mode 100644 index 0000000..9c2063b --- /dev/null +++ b/__test__/integration/biolink.test.ts @@ -0,0 +1,72 @@ +import { biolink } from '../../src/biolink'; + +describe('Test BioLinkModel class', () => { + test('test reverse with correct predicate', () => { + const res = biolink.reverse('treats'); + expect(res).toBe('treated_by'); + }); + + test('test reverse with correct predicate if it contains underscore', () => { + const res = biolink.reverse('treated_by'); + expect(res).toBe('treats'); + }); + + test('test reverse with predicate having symmetric equal to true', () => { + const res = biolink.reverse('correlated_with'); + expect(res).toBe('correlated_with'); + }); + + test('test predicate with no inverse property and symmetric not equal to true', () => { + const res = biolink.reverse('has_phenotype'); + expect(res).toBe('phenotype_of'); + }); + + test('test predicate not exist in biolink model', () => { + const res = biolink.reverse('haha'); + expect(res).toBeUndefined(); + }); + + test('if input not string, return undefined', () => { + //@ts-expect-error: Explicitly testing for wrong type + const res = biolink.reverse(['dd']); + expect(res).toBeUndefined(); + }); + + describe('Test getDescendants function', () => { + test('if input is in biolink model, return all its desendants and itself', () => { + const res = biolink.getDescendantClasses('MolecularEntity'); + expect(res).toContain('SmallMolecule'); + expect(res).toContain('NucleicAcidEntity'); + expect(res).toContain('MolecularEntity'); + }); + + test("if input is in biolink model but doesn't have descendants, return itself", () => { + const res = biolink.getDescendantClasses('Gene'); + expect(res).toEqual(['Gene']); + }); + + test('if input is not in biolink, return itself', () => { + const res = biolink.getDescendantClasses('Gene1'); + expect(res).toEqual('Gene1'); + }); + }); + + describe('Test getDescendantPredicates function', () => { + test('if input is in biolink model, return all its desendants and itself', () => { + const res = biolink.getDescendantPredicates('related_to'); + expect(res).toContain('subclass_of'); + expect(res).toContain('superclass_of'); + expect(res).toContain('related_to'); + }); + + test("if input is in biolink model but doesn't have descendants, return itself", () => { + const res = biolink.getDescendantPredicates('subclass_of'); + expect(res).toEqual(['subclass_of']); + }); + + test('if input is not in biolink, return itself', () => { + const res = biolink.getDescendantPredicates('Gene1'); + expect(res).toEqual(['Gene1']); + }); + }); +});