Skip to content

Commit

Permalink
validate GeneratorInfo #502
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Oct 2, 2024
1 parent 5e1b9f8 commit 7e94d80
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lphy-base/src/test/java/lphy/base/GeneratorValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import lphy.core.model.BasicFunction;
import lphy.core.model.GenerativeDistribution;
import lphy.core.model.GeneratorUtils;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.spi.Extension;
import lphy.core.spi.LPhyCoreLoader;
import lphy.core.spi.LPhyExtension;
Expand All @@ -16,7 +18,7 @@
import java.util.Map;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.*;

/**
* Validate if GenerativeDistribution and Function implemented correctly, also see
Expand Down Expand Up @@ -87,7 +89,13 @@ void validateGenerativeDistributions() {
fail(genDistCls.getName() + " does not implement getParams() !");
}

//TODO constructor, @GeneratorInfo
GeneratorInfo ginfo = GeneratorUtils.getGeneratorInfo(genDistCls);
assertNotNull(ginfo, genDistCls.getName());
// must have name and description
assertTrue(ginfo.name() != null && !ginfo.name().isEmpty(), genDistCls.getName());
assertTrue(ginfo.description() != null && !ginfo.description().isEmpty(), genDistCls.getName());

//TODO constructor, params

}

Expand All @@ -98,18 +106,24 @@ void validateGenerativeDistributions() {
@Test
void validateFunctions() {

for (Class<BasicFunction> functionClass : functions) {
System.out.println("Validating function : " + functionClass.getName());
for (Class<BasicFunction> funcCls : functions) {
System.out.println("Validating function : " + funcCls.getName());

try {
// Value<T> apply() {
Method apply = functionClass.getMethod("apply");
Method apply = funcCls.getMethod("apply");
} catch (NoSuchMethodException e) {
fail(functionClass.getName() + " does not implement apply() !");
fail(funcCls.getName() + " does not implement apply() !");
}
}

//TODO constructor, @GeneratorInfo, setParam in constructor, ...
GeneratorInfo ginfo = GeneratorUtils.getGeneratorInfo(funcCls);
assertNotNull(ginfo, funcCls.getName());
// must have name and description
assertTrue(ginfo.name() != null && !ginfo.name().isEmpty(), funcCls.getName());
assertTrue(ginfo.description() != null && !ginfo.description().isEmpty(), funcCls.getName());

//TODO constructor, params, setParam in constructor, ...
}

System.out.println("\nTotal " + functions.size() + " Generative Distributions.\n");
}
Expand Down

0 comments on commit 7e94d80

Please sign in to comment.