Search in sources :

Example 1 with NodeVariableDouble

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);
}
Also used : NodeVariableDouble(buildcraft.lib.expression.node.value.NodeVariableDouble) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) INodeLong(buildcraft.lib.expression.api.IExpressionNode.INodeLong) FunctionContext(buildcraft.lib.expression.FunctionContext) Test(org.junit.Test)

Aggregations

FunctionContext (buildcraft.lib.expression.FunctionContext)1 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)1 INodeLong (buildcraft.lib.expression.api.IExpressionNode.INodeLong)1 NodeVariableDouble (buildcraft.lib.expression.node.value.NodeVariableDouble)1 Test (org.junit.Test)1