use of de.be4.classicalb.core.parser.rules.RuleOperation in project probparsers by bendisposto.
the class RulesTransformation method translateGetRuleCounterExamplesOperator.
private void translateGetRuleCounterExamplesOperator(AOperatorExpression node) {
final PExpression pExpression = node.getIdentifiers().get(0);
final AIdentifierExpression id = (AIdentifierExpression) pExpression;
final String ruleName = id.getIdentifier().get(0).getText();
final AbstractOperation operation = allOperations.get(ruleName);
if (operation == null || !(operation instanceof RuleOperation)) {
errorList.add(new CheckException(String.format("'%s' does not match any rule visible to this machine.", ruleName), node));
return;
}
final RuleOperation rule = (RuleOperation) operation;
final String name = id.getIdentifier().get(0).getText() + RULE_COUNTER_EXAMPLE_VARIABLE_SUFFIX;
if (node.getIdentifiers().size() == 1) {
final AIdentifierExpression ctVariable = createIdentifier(name, pExpression);
final ARangeExpression range = createPositinedNode(new ARangeExpression(ctVariable), node);
node.replaceBy(range);
} else {
PExpression funcCall = getSetOfErrorMessagesByErrorType(name, node.getIdentifiers().get(1), rule.getNumberOfErrorTypes());
node.replaceBy(funcCall);
}
return;
}
use of de.be4.classicalb.core.parser.rules.RuleOperation in project prob2 by bendisposto.
the class RulesChecker method evalOperations.
public Map<AbstractOperation, OperationStatus> evalOperations(State state, Collection<AbstractOperation> operations) {
ArrayList<IEvalElement> formulas = new ArrayList<>();
for (AbstractOperation abstractOperation : operations) {
if (abstractOperation instanceof ComputationOperation || abstractOperation instanceof RuleOperation) {
formulas.add(rulesModel.getEvalElement(abstractOperation));
}
}
state.getStateSpace().subscribe(this, formulas);
Map<IEvalElement, AbstractEvalResult> values = state.getValues();
final Map<AbstractOperation, OperationStatus> states = new HashMap<>();
for (AbstractOperation op : operations) {
if (op instanceof RuleOperation) {
states.put(op, RuleStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
} else if (op instanceof ComputationOperation) {
states.put(op, ComputationStatus.valueOf(values.get(rulesModel.getEvalElement(op))));
}
}
return states;
}
use of de.be4.classicalb.core.parser.rules.RuleOperation 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.be4.classicalb.core.parser.rules.RuleOperation 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());
}
}
}
}
use of de.be4.classicalb.core.parser.rules.RuleOperation in project probparsers by bendisposto.
the class RulesMachineChecker method checkErrorTypesAttribute.
private void checkErrorTypesAttribute(POperationAttribute pOperationAttribute, LinkedList<PExpression> arguments) {
if (currentOperation instanceof RuleOperation) {
final RuleOperation rule = (RuleOperation) currentOperation;
if (arguments.size() == 1 && arguments.get(0) instanceof AIntegerExpression) {
AIntegerExpression intExpr = (AIntegerExpression) arguments.get(0);
rule.setErrrorTypes(intExpr);
} else {
errorList.add(new CheckException("Expected exactly one integer after ERROR_TYPES.", pOperationAttribute));
}
} else {
errorList.add(new CheckException("ERROR_TYPES is not an attribute of a FUNCTION or COMPUTATION operation.", pOperationAttribute));
}
return;
}
Aggregations