-
Notifications
You must be signed in to change notification settings - Fork 0
/
TripleExpressionTest.java
43 lines (39 loc) · 1.73 KB
/
TripleExpressionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package expression;
/**
* @author Georgiy Korneev ([email protected])
*/
public class TripleExpressionTest extends ExpressionTest {
public static void main(final String[] args) {
new TripleExpressionTest().run();
}
@Override
protected void test() {
super.test();
testExpression("10", new Const(10), (x, y, z) -> 10);
testExpression("x", new Variable("x"), (x, y, z) -> x);
testExpression("y", new Variable("y"), (x, y, z) -> y);
testExpression("z", new Variable("z"), (x, y, z) -> z);
testExpression("x+2", new Add(new Variable("x"), new Const(2)), (x, y, z) -> x + 2);
testExpression("2-y", new Subtract(new Const(2), new Variable("y")), (x, y, z) -> 2 - y);
testExpression("3*z", new Multiply(new Const(3), new Variable("z")), (x, y, z) -> 3 * z);
testExpression("x/-2", new Divide(new Variable("x"), new Const(-2)), (x, y, z) -> -x / 2);
testExpression(
"x*y+(z-1)/10",
new Add(
new Multiply(new Variable("x"), new Variable("y")),
new Divide(new Subtract(new Variable("z"), new Const(1)), new Const(10))
),
(x, y, z) -> x * y + (z - 1) / 10
);
}
private void testExpression(final String description, final TripleExpression actual, final TripleExpression expected) {
System.out.println("Testing " + description);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
assertEquals(String.format("f(%d, %d, %d)", i, j, k), actual.evaluate(i, j, k), expected.evaluate(i, j, k));
}
}
}
}
}