use of buildcraft.lib.expression.node.value.NodeVariableDouble in project BuildCraft by BuildCraft.
the class ExpressionTester method testVariables.
@Test
public void testVariables() {
FunctionContext ctx = new FunctionContext(DefaultContexts.createWithAll());
NodeVariableDouble someVariable = ctx.putVariableDouble("something");
someVariable.value = 0;
bakeAndCallDouble("something", 0, ctx);
someVariable.value = 1;
bakeAndCallDouble("something", 1, ctx);
NodeVariableObject<String> variant = ctx.putVariableString("variant");
String exp = "variant == 'gold'";
INodeBoolean expBool = bakeFunctionBoolean(exp, ctx);
variant.value = "nether_brick";
Assert.assertFalse(expBool.evaluate());
variant.value = "gold";
Assert.assertTrue(expBool.evaluate());
variant.value = "iron";
Assert.assertFalse(expBool.evaluate());
exp = "variant == 'wood' ? 0 : variant == 'steel' ? 1 : variant == 'obsidian' ? 2 : 3";
INodeLong expLong = bakeFunctionLong(exp, ctx);
variant.value = "wood";
Assert.assertEquals(expLong.evaluate(), 0);
variant.value = "steel";
Assert.assertEquals(expLong.evaluate(), 1);
variant.value = "obsidian";
Assert.assertEquals(expLong.evaluate(), 2);
variant.value = "some_other_value";
Assert.assertEquals(expLong.evaluate(), 3);
}
Aggregations