Search in sources :

Example 1 with Tuple

use of de.prob.translator.types.Tuple in project probparsers by bendisposto.

the class TranslatingVisitor method caseACoupleExpression.

@Override
public void caseACoupleExpression(ACoupleExpression node) {
    List<BObject> s = new ArrayList<BObject>();
    for (PExpression e : node.getList()) {
        e.apply(this);
        s.add(this.getResult());
    }
    this.setResult(new Tuple(s));
}
Also used : BObject(de.prob.translator.types.BObject) ArrayList(java.util.ArrayList) PExpression(de.be4.classicalb.core.parser.node.PExpression) Tuple(de.prob.translator.types.Tuple)

Example 2 with Tuple

use of de.prob.translator.types.Tuple in project probparsers by bendisposto.

the class TestTranslator method testTranslateTuple.

@Test
public void testTranslateTuple() throws Exception {
    Tuple o = (Tuple) Translator.translate("(1,2)");
    assertTrue(o.size() == 2);
    assertTrue(o.contains(Number.build("1")));
    assertTrue(o.contains(Number.build("2")));
    assertFalse(o.contains(Number.build("8")));
}
Also used : Tuple(de.prob.translator.types.Tuple) Test(org.junit.Test)

Example 3 with Tuple

use of de.prob.translator.types.Tuple in project prob2 by bendisposto.

the class RuleResult method transformCounterExamples.

private void transformCounterExamples(AbstractEvalResult abstractEvalResult) {
    EvalResult evalCurrent = (EvalResult) abstractEvalResult;
    TranslatedEvalResult translatedResult = null;
    try {
        translatedResult = evalCurrent.translate();
    } catch (Exception e) {
        /*- fall back solution if the result can not be parsed (e.g. {1,...,1000}) 
			 * should not not happen because MAX_DISPLAY_SET is set to -1 
			 * and hence, no truncated terms are delivered by ProBCore
			 * */
        final String message = evalCurrent.getValue().replaceAll("\"", "");
        counterExamples.add(new CounterExample(1, message));
        return;
    }
    if (translatedResult.getValue() instanceof de.prob.translator.types.Set) {
        de.prob.translator.types.Set set = (de.prob.translator.types.Set) translatedResult.getValue();
        for (final BObject object : set) {
            if (object instanceof Tuple) {
                final Tuple tuple = (Tuple) object;
                de.prob.translator.types.Number first = (de.prob.translator.types.Number) tuple.getFirst();
                int errorType = first.intValue();
                de.prob.translator.types.String second = (de.prob.translator.types.String) tuple.getSecond();
                String message = second.getValue();
                counterExamples.add(new CounterExample(errorType, message));
            } else {
                throw new AssertionError();
            }
        }
    } else if (translatedResult.getValue() instanceof de.prob.translator.types.Sequence) {
        de.prob.translator.types.Sequence sequence = (de.prob.translator.types.Sequence) translatedResult.getValue();
        for (int i = 1; i <= sequence.size(); i++) {
            de.prob.translator.types.String value = (de.prob.translator.types.String) sequence.get(i);
            String message = value.getValue();
            counterExamples.add(new CounterExample(i, message));
        }
    } else {
        // fall back: should not happen
        counterExamples.add(new CounterExample(1, evalCurrent.getValue()));
    }
}
Also used : BObject(de.prob.translator.types.BObject) Set(java.util.Set) EvalResult(de.prob.animator.domainobjects.EvalResult) TranslatedEvalResult(de.prob.animator.domainobjects.TranslatedEvalResult) AbstractEvalResult(de.prob.animator.domainobjects.AbstractEvalResult) TranslatedEvalResult(de.prob.animator.domainobjects.TranslatedEvalResult) Tuple(de.prob.translator.types.Tuple)

Aggregations

Tuple (de.prob.translator.types.Tuple)3 BObject (de.prob.translator.types.BObject)2 PExpression (de.be4.classicalb.core.parser.node.PExpression)1 AbstractEvalResult (de.prob.animator.domainobjects.AbstractEvalResult)1 EvalResult (de.prob.animator.domainobjects.EvalResult)1 TranslatedEvalResult (de.prob.animator.domainobjects.TranslatedEvalResult)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Test (org.junit.Test)1