Commit 7f99db01 authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Since expression outputs are now actually defined, make use of this fact.

Since expression's outputs now generally work with their type correctly, make
use of this to try and ensure an expression is evaluated correctly.  Also
make sure that the requested type does match the type outputted, and test
that this occurs (for now, just in BinaryExpression and Variable).

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_javization@10538 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 6ba1f037
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ final class MatlabExpressionBinaryOperation implements MatlabExpression, MatlabE
    @Override
    public String getCheckerOutput(CheckerGenerator generator, VariableType requestedType) {
        VariableType inputType = usedInputType();
        assert type().equals(requestedType);
        if (!type().equals(requestedType)) {
            throw new IllegalArgumentException("Requested output type is not the expression's output type!");
        }

        String lhsExp = m_lhs.getCheckerOutput(generator, inputType);
        String rhsExp = m_rhs.getCheckerOutput(generator, inputType);
+3 −1
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ public class Variable implements MatlabExpression, MatlabExpressionValue {

    @Override
    public String getCheckerOutput(CheckerGenerator generator, VariableType requestedType) {
        assert m_type.equals(requestedType);
        if (!type().equals(requestedType)) {
            throw new IllegalArgumentException("Requested output type is not the expression's output type!");
        }
        return m_name;
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -92,5 +92,16 @@ public class MatlabExpressionBinaryOperationTest {
        assertEquals("(5 == 6)", exp.getCheckerOutput(generator, exp.type()));
    }

    /**
     * Test operations fails when a requested type is invalid!
     */
    @Test(expected=IllegalArgumentException.class)
    public void testInvalidOutputType() {
        MatlabLiteral l = new MatlabLiteral("5"), r = new MatlabLiteral("6");
        MatlabExpressionBinaryOperation exp = new MatlabExpressionBinaryOperation(l, MatlabBinaryOperation.Equals, r);

        exp.getCheckerOutput(generator, new RealVariableType()); //Returns a boolean, so will fail.
    }

    CheckerGenerator generator = new CVC3Generator();
}
+11 −0
Original line number Diff line number Diff line
@@ -29,4 +29,15 @@ public class VariableTest {
        assertEquals(name, var.getCheckerOutput(null, new RealVariableType()));
        assertEquals(name+":"+generator.GenerateVariableType(type)+";", generator.GenerateVariableDecleration(var));
    }

    // Verify handling of invalid type to getCheckerOutput
    @Test(expected=IllegalArgumentException.class)
    public void testInvalidOutputType() {
        String name = "Var";
        VariableType type = new BooleanVariableType();

        Variable var = new Variable(name, type);

        var.getCheckerOutput(null, new RealVariableType()); //Returns a boolean, so will fail.
    }
}