/*
 * 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.cvc3generator;

import ca.mcmaster.cas.matlab2smt.VariableParser;
import ca.mcmaster.cas.tablularexpression.Cell;
import ca.mcmaster.cas.tablularexpression.HierarchcialGridCheckerGenerator;
import ca.mcmaster.cas.tablularexpression.HierarchicalCell;
import ca.mcmaster.cas.tablularexpression.HierarchicalGrid;
import ca.mcmaster.cas.tablularexpression.HierarchcialGridCheckerWalkerGenerator;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 *
 * @author Matthew Dawson <matthew@mjdsystems.ca>
 */
@RunWith(JUnit4.class)
public class HierarchicalGridCVC3GeneratorTest {

    // Exercise the cvc3 generator using a table designed in matlab.
    @Test
    public void exerciseCVC3Generator() {
        HierarchicalGrid grid = new HierarchicalGrid();
        List<HierarchicalCell> topCells = grid.getSubHiearchy();

        topCells.add(new HierarchicalCell("x > 0"));
        topCells.add(new HierarchicalCell("x == 0"));
        topCells.add(new HierarchicalCell("0 > x"));

        List<HierarchicalCell> nextGrid = topCells.get(1).getSubHiearchy();
        nextGrid.add(new HierarchicalCell("z > 0"));
        nextGrid.add(new HierarchicalCell("z == 0"));
        nextGrid.add(new HierarchicalCell("0 > z"));
        
        nextGrid.get(1).getSubHiearchy().add(new HierarchicalCell("z == 0"));

        String out = HierarchcialGridCheckerWalkerGenerator.GenerateCheckerFromGrid(grid, new HierarchicalGridCVC3Generator(new VariableParser("x,z"), 1));
        
        String expected = "ECHO \"begin1\";\n"+
"PUSH;\n"+
"QUERY (NOT ( (x > 0) AND (x = 0) ) AND\n"+
"NOT ( (x > 0) AND (0 > x) ) AND\n"+
"NOT ( (x = 0) AND (0 > x) ));\n"+
"POP;\n"+
"ECHO \"end1\";\n"+
"ECHO \"begin2\";\n"+
"PUSH;\n"+
"QUERY ((x > 0) OR (x = 0) OR (0 > x));\n"+
"POP;\n"+
"ECHO \"end2\";\n"+
"ECHO \"begin3\";\n"+
"PUSH;\n"+
"QUERY ((x = 0)) => (NOT ( (z > 0) AND (z = 0) ) AND\n"+
"NOT ( (z > 0) AND (0 > z) ) AND\n"+
"NOT ( (z = 0) AND (0 > z) ));\n"+
"POP;\n"+
"ECHO \"end3\";\n"+
"ECHO \"begin4\";\n"+
"PUSH;\n"+
"QUERY ((x = 0)) => ((z > 0) OR (z = 0) OR (0 > z));\n"+
"POP;\n"+
"ECHO \"end4\";\n"+
"ECHO \"begin5\";\n"+
"PUSH;\n"+
"QUERY ((z = 0) AND (x = 0)) => ();\n"+
"POP;\n"+
"ECHO \"end5\";\n"+
"ECHO \"begin6\";\n"+
"PUSH;\n"+
"QUERY ((z = 0) AND (x = 0)) => ((z = 0));\n"+
"POP;\n"+
"ECHO \"end6\";\n";
        assertEquals(expected, out);
    }
}
