import org.testng.annotations.Test; import norswap.autumn.TestFixture; public class ArithmeticTests extends TestFixture { Arithmetic arithmeticParser = new Arithmetic(); @Test public void testMathOperation() { this.rule = arithmeticParser.root; for (char op : new char[]{'+', '-', '*', '/'}) { System.out.println(op); success(" 1"+ op+"56"); success("1 "+op+" 1"); success("0"+op+"9"); success("1 "+op+" 1"); failure(""+op+" 1"); success("1 "+op+"2"+op+"3"+op+" 4+0"); success("1"+op+"2"+op+"3"+op+"4"); } success("1+2*3"); } @Test public void testMixedOperations() { this.rule = arithmeticParser.root; success("1 + 1 + 1000 -10"); success("1 + 90 * 85 / 3"); success("1 - 1 + 2"); success("1 / 2+ 1"); success("-1 + 1"); } @Test public void testBool(){ this.rule = arithmeticParser.root; success("false == true"); success("a == true"); success(" 1>= 5"); success("1 <= 2"); success("(1 == 2)"); success("true==(true==true)"); success("(true==true)==true"); success("a==(true==b)"); success("(a==true)==b"); } @Test public void testIfStatement() { this.rule = arithmeticParser.root; success("if (1 < 2) {a=1+2}"); success("if (1<2) { a = 1 + 3 }"); success("if (1 > 2) { 1 + 2 }"); success("if (2 == 2) {1+2}"); success("if (1 >= 2) { a = a * b + 2 }"); success("if ( (1==1) == true) { myBool = (1 <= 2)}"); success("if (1 != 2) { a == b }"); } @Test public void testIfElse() { this.rule = arithmeticParser.root; success("if (1 < 2) {1 + 1 + 1000} else {1 + 3}"); success("if (1 >= 8) {1 != 2} else {a == b}"); success("if (1 >= 8) {1 <= 2}"); } @Test public void testAssign() { this.rule = arithmeticParser.root; success("a=2"); success("a=-2"); success("a=b"); success("a= true"); } }