Search in sources :

Example 11 with RulesMachineRun

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

the class RulesMachineErrorsTest method testEnumerationError.

@Test
public void testEnumerationError() {
    RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations("RULE foo BODY RULE_FORALL x WHERE 1=1 EXPECT x = \"foo\" COUNTEREXAMPLE x END END");
    assertTrue(null != rulesMachineRun.getFirstError());
    assertEquals(ERROR_TYPES.PROB_ERROR, rulesMachineRun.getFirstError().getType());
    assertTrue(rulesMachineRun.getTotalNumberOfProBCliErrors().intValue() > 0);
    assertTrue(rulesMachineRun.getErrorList().size() > 0);
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) Test(org.junit.Test)

Example 12 with RulesMachineRun

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

the class RulesMachineErrorsTest method testRulesMachineWithWDError.

@Test
public void testRulesMachineWithWDError() {
    // @formatter:off
    RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations("RULE Rule1 BODY VAR xx IN xx := {1|->2}(3) END;RULE_FAIL COUNTEREXAMPLE \"fail\" END END", "RULE Rule2 DEPENDS_ON_RULE Rule1 BODY RULE_FAIL COUNTEREXAMPLE \"fail\" END END");
    System.out.println(rulesMachineRun.getFirstError());
    // @formatter:on
    assertTrue(rulesMachineRun.hasError());
    int numberofStatesExecuted = rulesMachineRun.getExecuteRun().getExecuteModelCommand().getNumberofStatesExecuted();
    assertEquals(1, numberofStatesExecuted);
    assertEquals(ERROR_TYPES.PROB_ERROR, rulesMachineRun.getFirstError().getType());
    assertTrue(rulesMachineRun.getTotalNumberOfProBCliErrors().intValue() > 0);
    System.out.println(rulesMachineRun.getRuleResults());
    // Rule1 is not checked because of the WD Error
    assertEquals(RuleStatus.NOT_CHECKED, rulesMachineRun.getRuleResults().getRuleResult("Rule1").getRuleState());
    // Rule2 is not checked because of the dependency to Rule1
    assertEquals(RuleStatus.NOT_CHECKED, rulesMachineRun.getRuleResults().getRuleResult("Rule2").getRuleState());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) Test(org.junit.Test)

Example 13 with RulesMachineRun

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

the class RulesMachineTest method testRulesMachineExample.

@Test
public void testRulesMachineExample() {
    RulesMachineRun rulesMachineRun = startRulesMachineRun(dir + "RulesMachineExample.rmch");
    assertEquals(false, rulesMachineRun.hasError());
    State finalState = rulesMachineRun.getExecuteRun().getExecuteModelCommand().getFinalState();
    ComputationStatuses compResult = new ComputationStatuses(rulesMachineRun.getRulesProject(), finalState);
    assertEquals(ComputationStatus.EXECUTED, compResult.getResult("COMP_comp1"));
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) State(de.prob.statespace.State) ComputationStatuses(de.prob.model.brules.ComputationStatuses) Test(org.junit.Test)

Example 14 with RulesMachineRun

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

the class RulesMachineTest method testExtractingAllCounterExample.

@Test
public void testExtractingAllCounterExample() {
    File file = createRulesMachineFile("OPERATIONS RULE Rule1 BODY RULE_FAIL x WHEN x : 1..1000 COUNTEREXAMPLE STRING_FORMAT(\"This is a long counter example message including a unique number to test that the extracted B value will not be truncated: ~w\", x) END END");
    RulesMachineRun rulesMachineRun = new RulesMachineRun(file);
    rulesMachineRun.setMaxNumberOfReportedCounterExamples(1000);
    rulesMachineRun.start();
    System.out.println(rulesMachineRun.getRuleResults().getRuleResult("Rule1").getCounterExamples());
    assertEquals(1000, rulesMachineRun.getRuleResults().getRuleResult("Rule1").getCounterExamples().size());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) File(java.io.File) Test(org.junit.Test)

Example 15 with RulesMachineRun

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

the class RulesMachineTest method testReuseStateSpace.

@Test
public void testReuseStateSpace() throws IOException {
    String ruleWithWDError = "RULE Rule1 BODY VAR xx IN xx := {1|->2}(3) END;RULE_FAIL WHEN 1=2 COUNTEREXAMPLE \"fail\" END END";
    RulesMachineRun rulesMachineRun = startRulesMachineRunWithOperations(ruleWithWDError);
    BigInteger numberAfterFirstRun = rulesMachineRun.getTotalNumberOfProBCliErrors();
    RulesMachineRun rulesMachineRun2 = new RulesMachineRun(RulesTestUtil.createRulesMachineFileContainingOperations(ruleWithWDError).getAbsoluteFile());
    rulesMachineRun2.setStateSpace(rulesMachineRun.getStateSpace());
    rulesMachineRun2.start();
    BigInteger numberAfterSecondRun = rulesMachineRun2.getTotalNumberOfProBCliErrors();
    assertTrue(numberAfterSecondRun.intValue() > numberAfterFirstRun.intValue());
}
Also used : RulesMachineRun(de.prob.model.brules.RulesMachineRun) BigInteger(java.math.BigInteger) 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