Search in sources :

Example 1 with RuleResults

use of de.prob.model.brules.RuleResults 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 2 with RuleResults

use of de.prob.model.brules.RuleResults in project prob2 by bendisposto.

the class RulesTestUtil method checkRulesMachineRunForConsistency.

public static void checkRulesMachineRunForConsistency(RulesMachineRun rulesMachineRun) {
    RulesProject rulesProject = rulesMachineRun.getRulesProject();
    RuleResults ruleResults = rulesMachineRun.getRuleResults();
    Map<String, RuleResult> ruleResultMap = ruleResults.getRuleResultMap();
    for (AbstractOperation abstractOperation : rulesProject.getOperationsMap().values()) {
        if (abstractOperation instanceof RuleOperation) {
            String ruleName = abstractOperation.getName();
            assertTrue(String.format("Rule operation '%s' is not contained in the result map.", ruleName), ruleResultMap.containsKey(ruleName));
            RuleResult ruleResult = ruleResultMap.get(ruleName);
            if (ruleResult.getRuleState() == RuleStatus.FAIL) {
                assertTrue(String.format("No violation found but rule failed: '%s'", ruleName), ruleResult.getNumberOfViolations() > 0);
            }
            if (ruleResult.getRuleState() == RuleStatus.NOT_CHECKED) {
                List<String> notCheckedCauses = ruleResult.getFailedDependencies();
                assertTrue(String.format("There is no cause why rule '%s' is not checked.", ruleName), !notCheckedCauses.isEmpty());
            }
        }
    }
}
Also used : RuleResults(de.prob.model.brules.RuleResults) RuleOperation(de.be4.classicalb.core.parser.rules.RuleOperation) AbstractOperation(de.be4.classicalb.core.parser.rules.AbstractOperation) RulesProject(de.be4.classicalb.core.parser.rules.RulesProject) RuleResult(de.prob.model.brules.RuleResult)

Aggregations

RuleOperation (de.be4.classicalb.core.parser.rules.RuleOperation)2 RuleResult (de.prob.model.brules.RuleResult)2 RuleResults (de.prob.model.brules.RuleResults)2 AbstractOperation (de.be4.classicalb.core.parser.rules.AbstractOperation)1 RulesProject (de.be4.classicalb.core.parser.rules.RulesProject)1 ResultSummary (de.prob.model.brules.RuleResults.ResultSummary)1 RulesMachineRun (de.prob.model.brules.RulesMachineRun)1 Test (org.junit.Test)1