Search in sources :

Example 1 with RulesMachineRun

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));
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) Test(org.junit.Test)

Example 2 with RulesMachineRun

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));
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) RuleResults(de.prob.model.brules.RuleResults) RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) ResultSummary(de.prob.model.brules.RuleResults.ResultSummary) RuleResult(de.prob.model.brules.RuleResult) Test(org.junit.Test)

Example 3 with RulesMachineRun

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());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) File(java.io.File) Test(org.junit.Test)

Example 4 with RulesMachineRun

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());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) HashMap(java.util.HashMap) File(java.io.File) Test(org.junit.Test)

Example 5 with RulesMachineRun

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());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) CounterExample(de.prob.model.brules.RuleResult.CounterExample) RuleResult(de.prob.model.brules.RuleResult) Test(org.junit.Test)

Aggregations

RulesMachineRun (de.prob.model.brules.RulesMachineRun)20 Test (org.junit.Test)18 File (java.io.File)6 RuleResult (de.prob.model.brules.RuleResult)3 HashMap (java.util.HashMap)2 BException (de.be4.classicalb.core.parser.exceptions.BException)1 RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)1 ComputationStatuses (de.prob.model.brules.ComputationStatuses)1 CounterExample (de.prob.model.brules.RuleResult.CounterExample)1 RuleResults (de.prob.model.brules.RuleResults)1 ResultSummary (de.prob.model.brules.RuleResults.ResultSummary)1 State (de.prob.statespace.State)1 BigInteger (java.math.BigInteger)1