use of de.prob.model.brules.RulesMachineRun in project prob2 by bendisposto.
the class RulesMachineTest method testMachineWithFailingRule.
@Test
public void testMachineWithFailingRule() {
// @formatter:off
RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations("RULE Rule1 RULEID id1 BODY RULE_FAIL COUNTEREXAMPLE \"foo\" END END", "RULE Rule2 DEPENDS_ON_RULE Rule1 BODY RULE_FAIL WHEN 1=2 COUNTEREXAMPLE \"fail\" END END");
System.out.println(rulesMachineRun.getFirstError());
// @formatter:on
assertTrue(!rulesMachineRun.hasError());
System.out.println(rulesMachineRun.getRuleResults());
assertTrue(rulesMachineRun.getRuleResults().getRuleResult("Rule1").hasFailed());
assertEquals(FAIL, rulesMachineRun.getRuleResults().getRuleResult("Rule1").getRuleState());
assertEquals(NOT_CHECKED, rulesMachineRun.getRuleResults().getRuleResult("Rule2").getRuleState());
assertEquals("Rule1", rulesMachineRun.getRuleResults().getRuleResult("Rule2").getFailedDependencies().get(0));
}
use of de.prob.model.brules.RulesMachineRun in project prob2 by bendisposto.
the class RulesMachineTest method testSimpleRulesMachine.
@Test
public void testSimpleRulesMachine() throws IOException {
RulesMachineRun rulesMachineRun = startRulesMachineRun(dir + "SimpleRulesMachine.rmch");
assertEquals(false, rulesMachineRun.hasError());
assertTrue(rulesMachineRun.getErrorList().isEmpty());
assertEquals(null, rulesMachineRun.getFirstError());
RuleResults ruleResults = rulesMachineRun.getRuleResults();
ResultSummary summary = ruleResults.getSummary();
// summary is created only once
assertEquals(summary, ruleResults.getSummary());
assertEquals(4, ruleResults.getRuleResultList().size());
RuleResult rule1Result = ruleResults.getRuleResult("Rule1");
assertEquals(RuleStatus.SUCCESS, rule1Result.getRuleState());
RuleOperation rule1Operation = rule1Result.getRuleOperation();
assertEquals("Rule1", rule1Operation.getName());
assertTrue("Should be empty", rule1Result.getNotCheckedDependencies().isEmpty());
RuleResult result2 = ruleResults.getRuleResult("Rule2");
assertEquals(RuleStatus.FAIL, result2.getRuleState());
String message = result2.getCounterExamples().get(0).getMessage();
assertEquals("ERROR2", message);
assertEquals(NOT_CHECKED, ruleResults.getRuleResult("Rule3").getRuleState());
assertEquals("Rule2", ruleResults.getRuleResult("Rule3").getFailedDependencies().get(0));
}
use of de.prob.model.brules.RulesMachineRun in project prob2 by bendisposto.
the class RulesMachineTest method testChangeNumberOfReportedCounterExamples.
@Test
public void testChangeNumberOfReportedCounterExamples() {
File file = createRulesMachineFile("OPERATIONS RULE Rule1 BODY RULE_FAIL x WHEN x : 1..1000 COUNTEREXAMPLE STRING_FORMAT(\"~w\", x) END END");
RulesMachineRun rulesMachineRun = new RulesMachineRun(file);
rulesMachineRun.setMaxNumberOfReportedCounterExamples(20);
rulesMachineRun.start();
System.out.println(rulesMachineRun.getRuleResults().getRuleResult("Rule1").getCounterExamples());
assertEquals(20, rulesMachineRun.getRuleResults().getRuleResult("Rule1").getCounterExamples().size());
}
use of de.prob.model.brules.RulesMachineRun in project prob2 by bendisposto.
the class RulesMachineTest method testInjectConstants.
@Test
public void testInjectConstants() {
File file = createRulesMachineFile("CONSTANTS k PROPERTIES k : STRING OPERATIONS RULE Rule1 BODY IF k = \"abc\" THEN RULE_FAIL COUNTEREXAMPLE \"fail\" END END END");
Map<String, String> constantValuesToBeInjected = new HashMap<>();
constantValuesToBeInjected.put("k", "abc");
RulesMachineRun rulesMachineRun = new RulesMachineRun(file, null, constantValuesToBeInjected);
rulesMachineRun.start();
assertTrue(rulesMachineRun.getRuleResults().getRuleResult("Rule1").hasFailed());
}
use of de.prob.model.brules.RulesMachineRun in project prob2 by bendisposto.
the class RulesMachineTest method testCounterExample.
@Test
public void testCounterExample() {
RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations("RULE foo BODY RULE_FAIL ERROR_TYPE 1 COUNTEREXAMPLE \"error\"END END");
assertEquals(null, rulesMachineRun.getFirstError());
RuleResult ruleResult = rulesMachineRun.getRuleResults().getRuleResult("foo");
List<CounterExample> counterExamples = ruleResult.getCounterExamples();
assertEquals(1, counterExamples.size());
CounterExample counterExample = counterExamples.get(0);
assertEquals(1, counterExample.getErrorType());
}
Aggregations