From 7fb36c436c071dcd527d5e592471f1b7f2d5a81f Mon Sep 17 00:00:00 2001 From: Leonardo macOS Date: Thu, 29 Aug 2024 12:55:07 +0200 Subject: [PATCH] Set up basic infrastructure for testing in chinese, turkish and dutch --- .../chinese/PpktIndividualChineseTest.java | 123 ++++++++++++++++++ .../impl/dutch/PpktIndividualDutchTest.java | 123 ++++++++++++++++++ .../turkish/PpktIndividualTurkishTest.java | 123 ++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/chinese/PpktIndividualChineseTest.java create mode 100644 src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/dutch/PpktIndividualDutchTest.java create mode 100644 src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/turkish/PpktIndividualTurkishTest.java diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/chinese/PpktIndividualChineseTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/chinese/PpktIndividualChineseTest.java new file mode 100644 index 0000000..763ffe4 --- /dev/null +++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/chinese/PpktIndividualChineseTest.java @@ -0,0 +1,123 @@ +package org.monarchinitiative.phenopacket2prompt.output.impl.chinese; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.monarchinitiative.phenol.base.PhenolRuntimeException; +import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex; +import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualBase; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualInfoGenerator; + +import java.util.function.Supplier; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class PpktIndividualChineseTest extends PPKtIndividualBase{ + + + + private static Stream testGetIndividualDescription() { + return Stream.of( + new TestIndividual("46 year old female, infantile onset", + female46yearsInfantileOnset(), new TestOutcome.Ok("La paziente era una donna di 46 anni. L'inizio della malattia avvenne durante il periodo infantile.")), + new TestIndividual("male 4 months, congenital onset", + male4monthsCongenitalOnset(), new TestOutcome.Ok("Il paziente era un infante maschio di 4 mesi. L'inizio della malattia avvenne alla nascita.")), + new TestIndividual("female, no onset", + femaleNoAge(), new TestOutcome.Ok("La paziente era di sesso femminile e di età non specificata. Non venne indicata l'età dell'inizio della malattia.")), + new TestIndividual("female, no HPOs", + femaleNoHPOs(), new TestOutcome.Error(() -> new PhenolRuntimeException("Nessuna anomalia fenotipica"))), + new TestIndividual("unknown sex, no 4yo", + unknownSex4YearsOnset(), new TestOutcome.Ok("Il paziente era di sesso e di età non specificati. L'inizio della malattia avvenne da bambino.")) + ); + } + + + + @ParameterizedTest + @MethodSource("testGetIndividualDescription") + void testEvaluateExpression(TestIndividual testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualChinese(); + PpktIndividual ppkti = testCase.ppktIndividual(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.getIndividualDescription(ppkti), + "Incorrect evaluation for: " + testCase.description()); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.getIndividualDescription(ppkti), + "Incorrect error handling for: " + testCase.description()); + } + } + + + + private static Stream testGetPPKtSex() { + return Stream.of( + new TestIdvlHeShe("female", + PhenopacketSex.FEMALE, new TestOutcome.Ok("la paziente")), + new TestIdvlHeShe("male", + PhenopacketSex.MALE, new TestOutcome.Ok("il paziente")), + new TestIdvlHeShe("proband", + PhenopacketSex.UNKNOWN, new TestOutcome.Ok("il soggetto")) + ); + } + + @ParameterizedTest + @MethodSource("testGetPPKtSex") + void testPPKtSex(TestIdvlHeShe testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualChinese(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.heSheIndividual(testCase.ppktSex())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.heSheIndividual(testCase.ppktSex()), + "Incorrect error handling for: " + testCase.description()); + } + } + + + +//public record TestIdvlAtAge(String description, PhenopacketAge ppktAge, TestOutcome expectedOutcome) {} + + + + + private static Stream testIndlAtAge() { + return Stream.of( + new TestIdvlAtAge("congenital", + congenital, new TestOutcome.Ok("Alla nascita")), + new TestIdvlAtAge("infantile", + infantile, new TestOutcome.Ok("Durante il periodo infantile")), + new TestIdvlAtAge("childhood age", + childhood, new TestOutcome.Ok("Da bambino")), + new TestIdvlAtAge("46 years old", + p46y, new TestOutcome.Ok("All'età di 46 anni")) + ); + } + + + @ParameterizedTest + @MethodSource("testIndlAtAge") + void testPPKtSex(TestIdvlAtAge testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualChinese(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.atAgeForVignette(testCase.ppktAge())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.atAgeForVignette(testCase.ppktAge()), + "Incorrect error handling for: " + testCase.description()); + } + + + } + + + + + + +} diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/dutch/PpktIndividualDutchTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/dutch/PpktIndividualDutchTest.java new file mode 100644 index 0000000..87f24cb --- /dev/null +++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/dutch/PpktIndividualDutchTest.java @@ -0,0 +1,123 @@ +package org.monarchinitiative.phenopacket2prompt.output.impl.dutch; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.monarchinitiative.phenol.base.PhenolRuntimeException; +import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex; +import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualBase; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualInfoGenerator; + +import java.util.function.Supplier; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class PpktIndividualDutchTest extends PPKtIndividualBase{ + + + + private static Stream testGetIndividualDescription() { + return Stream.of( + new TestIndividual("46 year old female, infantile onset", + female46yearsInfantileOnset(), new TestOutcome.Ok("La paziente era una donna di 46 anni. L'inizio della malattia avvenne durante il periodo infantile.")), + new TestIndividual("male 4 months, congenital onset", + male4monthsCongenitalOnset(), new TestOutcome.Ok("Il paziente era un infante maschio di 4 mesi. L'inizio della malattia avvenne alla nascita.")), + new TestIndividual("female, no onset", + femaleNoAge(), new TestOutcome.Ok("La paziente era di sesso femminile e di età non specificata. Non venne indicata l'età dell'inizio della malattia.")), + new TestIndividual("female, no HPOs", + femaleNoHPOs(), new TestOutcome.Error(() -> new PhenolRuntimeException("Nessuna anomalia fenotipica"))), + new TestIndividual("unknown sex, no 4yo", + unknownSex4YearsOnset(), new TestOutcome.Ok("Il paziente era di sesso e di età non specificati. L'inizio della malattia avvenne da bambino.")) + ); + } + + + + @ParameterizedTest + @MethodSource("testGetIndividualDescription") + void testEvaluateExpression(TestIndividual testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualDutch(); + PpktIndividual ppkti = testCase.ppktIndividual(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.getIndividualDescription(ppkti), + "Incorrect evaluation for: " + testCase.description()); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.getIndividualDescription(ppkti), + "Incorrect error handling for: " + testCase.description()); + } + } + + + + private static Stream testGetPPKtSex() { + return Stream.of( + new TestIdvlHeShe("female", + PhenopacketSex.FEMALE, new TestOutcome.Ok("la paziente")), + new TestIdvlHeShe("male", + PhenopacketSex.MALE, new TestOutcome.Ok("il paziente")), + new TestIdvlHeShe("proband", + PhenopacketSex.UNKNOWN, new TestOutcome.Ok("il soggetto")) + ); + } + + @ParameterizedTest + @MethodSource("testGetPPKtSex") + void testPPKtSex(TestIdvlHeShe testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualDutch(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.heSheIndividual(testCase.ppktSex())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.heSheIndividual(testCase.ppktSex()), + "Incorrect error handling for: " + testCase.description()); + } + } + + + +//public record TestIdvlAtAge(String description, PhenopacketAge ppktAge, TestOutcome expectedOutcome) {} + + + + + private static Stream testIndlAtAge() { + return Stream.of( + new TestIdvlAtAge("congenital", + congenital, new TestOutcome.Ok("Alla nascita")), + new TestIdvlAtAge("infantile", + infantile, new TestOutcome.Ok("Durante il periodo infantile")), + new TestIdvlAtAge("childhood age", + childhood, new TestOutcome.Ok("Da bambino")), + new TestIdvlAtAge("46 years old", + p46y, new TestOutcome.Ok("All'età di 46 anni")) + ); + } + + + @ParameterizedTest + @MethodSource("testIndlAtAge") + void testPPKtSex(TestIdvlAtAge testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualDutch(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.atAgeForVignette(testCase.ppktAge())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.atAgeForVignette(testCase.ppktAge()), + "Incorrect error handling for: " + testCase.description()); + } + + + } + + + + + + +} diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/turkish/PpktIndividualTurkishTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/turkish/PpktIndividualTurkishTest.java new file mode 100644 index 0000000..6dc3aa2 --- /dev/null +++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/turkish/PpktIndividualTurkishTest.java @@ -0,0 +1,123 @@ +package org.monarchinitiative.phenopacket2prompt.output.impl.turkish; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.monarchinitiative.phenol.base.PhenolRuntimeException; +import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex; +import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualBase; +import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualInfoGenerator; + +import java.util.function.Supplier; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class PpktIndividualTurkishTest extends PPKtIndividualBase{ + + + + private static Stream testGetIndividualDescription() { + return Stream.of( + new TestIndividual("46 year old female, infantile onset", + female46yearsInfantileOnset(), new TestOutcome.Ok("La paziente era una donna di 46 anni. L'inizio della malattia avvenne durante il periodo infantile.")), + new TestIndividual("male 4 months, congenital onset", + male4monthsCongenitalOnset(), new TestOutcome.Ok("Il paziente era un infante maschio di 4 mesi. L'inizio della malattia avvenne alla nascita.")), + new TestIndividual("female, no onset", + femaleNoAge(), new TestOutcome.Ok("La paziente era di sesso femminile e di età non specificata. Non venne indicata l'età dell'inizio della malattia.")), + new TestIndividual("female, no HPOs", + femaleNoHPOs(), new TestOutcome.Error(() -> new PhenolRuntimeException("Nessuna anomalia fenotipica"))), + new TestIndividual("unknown sex, no 4yo", + unknownSex4YearsOnset(), new TestOutcome.Ok("Il paziente era di sesso e di età non specificati. L'inizio della malattia avvenne da bambino.")) + ); + } + + + + @ParameterizedTest + @MethodSource("testGetIndividualDescription") + void testEvaluateExpression(TestIndividual testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualTurkish(); + PpktIndividual ppkti = testCase.ppktIndividual(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.getIndividualDescription(ppkti), + "Incorrect evaluation for: " + testCase.description()); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.getIndividualDescription(ppkti), + "Incorrect error handling for: " + testCase.description()); + } + } + + + + private static Stream testGetPPKtSex() { + return Stream.of( + new TestIdvlHeShe("female", + PhenopacketSex.FEMALE, new TestOutcome.Ok("la paziente")), + new TestIdvlHeShe("male", + PhenopacketSex.MALE, new TestOutcome.Ok("il paziente")), + new TestIdvlHeShe("proband", + PhenopacketSex.UNKNOWN, new TestOutcome.Ok("il soggetto")) + ); + } + + @ParameterizedTest + @MethodSource("testGetPPKtSex") + void testPPKtSex(TestIdvlHeShe testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualTurkish(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.heSheIndividual(testCase.ppktSex())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.heSheIndividual(testCase.ppktSex()), + "Incorrect error handling for: " + testCase.description()); + } + } + + + +//public record TestIdvlAtAge(String description, PhenopacketAge ppktAge, TestOutcome expectedOutcome) {} + + + + + private static Stream testIndlAtAge() { + return Stream.of( + new TestIdvlAtAge("congenital", + congenital, new TestOutcome.Ok("Alla nascita")), + new TestIdvlAtAge("infantile", + infantile, new TestOutcome.Ok("Durante il periodo infantile")), + new TestIdvlAtAge("childhood age", + childhood, new TestOutcome.Ok("Da bambino")), + new TestIdvlAtAge("46 years old", + p46y, new TestOutcome.Ok("All'età di 46 anni")) + ); + } + + + @ParameterizedTest + @MethodSource("testIndlAtAge") + void testPPKtSex(TestIdvlAtAge testCase) { + PPKtIndividualInfoGenerator generator = new PpktIndividualTurkish(); + switch (testCase.expectedOutcome()) { + case TestOutcome.Ok(String expectedResult) -> + assertEquals(expectedResult, generator.atAgeForVignette(testCase.ppktAge())); + case TestOutcome.Error(Supplier exceptionSupplier) -> + assertThrows(exceptionSupplier.get().getClass(), + () -> generator.atAgeForVignette(testCase.ppktAge()), + "Incorrect error handling for: " + testCase.description()); + } + + + } + + + + + + +}