@Test public void testParseSmallTimesExpression() { Expression parsedTimes = parser.parse("3*2"); assertTrue( "Parsing a multiplication should return a TimesExpression...", parsedTimes instanceof TimesExpression); assertTrue( "...with a LHS of type IntExpression ...", ((TimesExpression) parsedTimes).getLHS() instanceof IntExpression); IntExpression lhs = (IntExpression) ((TimesExpression) parsedTimes).getLHS(); assertTrue( "... and a RHS of type IntExpression.", ((TimesExpression) parsedTimes).getRHS() instanceof IntExpression); IntExpression rhs = (IntExpression) ((TimesExpression) parsedTimes).getRHS(); assertEquals("Our LHS should have value 3", 3, lhs.getValue()); assertEquals("and our RHS should have value 2", 2, rhs.getValue()); }
@Test public void testParseSmallPlusExpression() { Expression parsedPlus = parser.parse("12+119"); assertTrue( "parsing an int-plus-int should return a plus expression", parsedPlus instanceof PlusExpression); assertTrue( "with a LHS of type IntExpression", ((PlusExpression) parsedPlus).getLHS() instanceof IntExpression); IntExpression lhs = (IntExpression) ((PlusExpression) parsedPlus).getLHS(); assertTrue( "and with a RHS of type IntExpression", ((PlusExpression) parsedPlus).getRHS() instanceof IntExpression); IntExpression rhs = (IntExpression) ((PlusExpression) parsedPlus).getRHS(); assertEquals("our LHS should have value 12", 12, lhs.getValue()); assertEquals("our RHS should have value 119", 119, rhs.getValue()); }