Commit 15a8649f authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Test simple parsing of operators.

Test that each operator is parsed in properly.  Currently only tests implemented
operators, with more to follow.

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_javization@10703 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 9a3b0f7d
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 Matthew Dawson <matthew@mjdsystems.ca>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ca.mcmaster.cas.matlab2smt;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.Parameterized.Parameter;

import java.util.Arrays;
import java.util.Collection;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

/** This test simply tests that each operator parses correctly.
 *
 * This is a simply parametrized test set that only deals with the various operators MatlabParser deals with.  It avoids
 * all the other details (it just uses literals for input).  It also avoids any dependency on generators.
 *
 * @author Matthew Dawson <matthew@mjdsystems.ca>
 */
@RunWith(Parameterized.class)
public class MatlabParserOperatorParseTest {
    @Parameters
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {"+", MatlabBinaryOperation.Addition, null},
                {"*", MatlabBinaryOperation.Multiplication, null},
                {">", MatlabBinaryOperation.GreaterThen, null},
                {"==", MatlabBinaryOperation.Equals, null},
                {"&&", MatlabBinaryOperation.BooleanAnd, null}
        });
    }
    @Parameter
    public String inputSymbol;

    @Parameter(value = 1)
    public MatlabBinaryOperation bop;

    @Parameter(value = 2)
    public MatlabUnaryOperation uop;

    @Test
    public void doTest() {
        if (bop != null) {
            // Binary op to test ...
            MatlabParser parser = new MatlabParser(null, "1" + inputSymbol + "2\n");
            MatlabExpressionBinaryOperation exp = (MatlabExpressionBinaryOperation)parser.getRootExpression();

            assertThat(exp.m_op, is(bop));
            assertThat(((MatlabLiteral)exp.m_lhs).m_value, is("1"));
            assertThat(((MatlabLiteral)exp.m_rhs).m_value, is("2"));
        } else {
            assertThat(false, is(true));
        }
    }
}