Created
November 27, 2010 16:01
-
-
Save timaschew/718012 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testMultiDigits() { | |
testResult("123", new Double(123)); | |
} | |
@Test | |
public void testFractionalDecimal() { | |
testResult("123.456", new Double(123.456)); | |
} | |
@Test | |
public void testAssignment1a() { | |
testResult("x=7", new Double(7)); | |
} | |
@Test | |
public void testAssignment1b() { | |
testResult("x = 7", new Double(7)); | |
} | |
@Test | |
public void testVarNames() { | |
testResult("xyz=10", new Double(10)); | |
testResult("hallo_ichbineine_123456789UltralangeVARIABLE = 10" + | |
"hallo_ichbineine_123456789UltralangeVARIABLE *= 1.5", new Double(15)); | |
} | |
@Test | |
public void testAssignment2() { | |
testResult("x=5*2*3/15", new Double(2)); | |
} | |
@Test | |
public void testAssignment3() { | |
testResult("x = 5 + 2 + 10", new Double(17)); | |
} | |
@Test | |
public void whiteSpaceTest1() { | |
testResult("3 * 3", new Double(9)); | |
} | |
@Test | |
public void whiteSpaceTest2() { | |
testResult(" ( 3 * 3 ) ", new Double(9)); | |
} | |
@Test | |
public void testAssignment4() { | |
testResult("x = (3 * 3)", new Double(9)); | |
} | |
@Test | |
public void testAssignment5() { | |
testResult("x = (3 * 3) x = x * 2", new Double(18)); | |
} | |
@Test | |
public void testAssignment6() { | |
testResult("x = (3 * 3) x = x * 2 y = x+2", new Double(20)); | |
} | |
@Test | |
public void testAssignment7() { | |
testResult("x = 3 * 3 y = x * z", new Double(0)); | |
} | |
@Test | |
public void testAssignmentEquals1() { | |
testResult("x = 2 x *= 3", new Double(6)); | |
} | |
@Test | |
public void testAssignmentEquals2() { | |
testResult("x=2x*=2+2*4", new Double(20)); | |
} | |
@Test | |
public void testAssignmentEquals3() { | |
testResult("x = 2 x *= 5 y = x * 3", new Double(30)); | |
} | |
@Test | |
public void testAssignmentEquals4() { | |
testResult("x = 10 x+= 3", new Double(13)); | |
} | |
@Test | |
public void testBla1() { | |
testResult("x=5 x*=5 x", new Double(25)); | |
} | |
@Test | |
public void testBla2() { | |
testResult("x=16 y=2 x/4*y", new Double(8)); | |
} | |
@Test | |
public void testUndefinedVars() { | |
testResult("x", new Double(0)); | |
testResult("x *= 4", new Double(4)); | |
testResult("x += 1", new Double(1)); | |
} | |
public void testResult(String string, Double expected) { | |
Double d = Interpreter.eval(string); | |
Assert.assertEquals(expected, d); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment