Skip to content

Commit 30c4d12

Browse files
committed
Implement operator_subtract
1 parent d41baed commit 30c4d12

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@ std::string OperatorBlocks::description() const
2020
void OperatorBlocks::registerBlocks(IEngine *engine)
2121
{
2222
engine->addCompileFunction(this, "operator_add", &compileAdd);
23+
engine->addCompileFunction(this, "operator_subtract", &compileSubtract);
2324
}
2425

2526
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
2627
{
2728
return compiler->createAdd(compiler->addInput("NUM1"), compiler->addInput("NUM2"));
2829
}
30+
31+
CompilerValue *OperatorBlocks::compileSubtract(Compiler *compiler)
32+
{
33+
return compiler->createSub(compiler->addInput("NUM1"), compiler->addInput("NUM2"));
34+
}

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,22 @@ TEST_F(OperatorBlocksTest, Add)
4545
ASSERT_EQ(valueList->size(), 1);
4646
ASSERT_EQ(Value(values[0]), 8.2);
4747
}
48+
49+
TEST_F(OperatorBlocksTest, Subtract)
50+
{
51+
auto target = std::make_shared<Sprite>();
52+
ScriptBuilder builder(m_extension.get(), m_engine, target);
53+
54+
builder.addBlock("operator_subtract");
55+
builder.addValueInput("NUM1", 5.7);
56+
builder.addValueInput("NUM2", 2.5);
57+
builder.captureBlockReturnValue();
58+
59+
builder.build();
60+
builder.run();
61+
62+
List *valueList = builder.capturedValues();
63+
ValueData *values = valueList->data();
64+
ASSERT_EQ(valueList->size(), 1);
65+
ASSERT_EQ(Value(values[0]), 3.2);
66+
}

0 commit comments

Comments
 (0)