Skip to content

Commit c040d5e

Browse files
committed
Implement operator_equals
1 parent 3a39a57 commit c040d5e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/dev/blocks/operatorblocks.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2626
engine->addCompileFunction(this, "operator_divide", &compileDivide);
2727
engine->addCompileFunction(this, "operator_random", &compileRandom);
2828
engine->addCompileFunction(this, "operator_lt", &compileLt);
29+
engine->addCompileFunction(this, "operator_equals", &compileEquals);
2930
}
3031

3132
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -59,3 +60,8 @@ CompilerValue *OperatorBlocks::compileLt(Compiler *compiler)
5960
{
6061
return compiler->createCmpLT(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
6162
}
63+
64+
CompilerValue *OperatorBlocks::compileEquals(Compiler *compiler)
65+
{
66+
return compiler->createCmpEQ(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
67+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OperatorBlocks : public IExtension
2424
static CompilerValue *compileDivide(Compiler *compiler);
2525
static CompilerValue *compileRandom(Compiler *compiler);
2626
static CompilerValue *compileLt(Compiler *compiler);
27+
static CompilerValue *compileEquals(Compiler *compiler);
2728
};
2829

2930
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,34 @@ TEST_F(OperatorBlocksTest, Lt)
194194
ASSERT_EQ(Value(values[1]), false);
195195
ASSERT_EQ(Value(values[2]), false);
196196
}
197+
198+
TEST_F(OperatorBlocksTest, Equals)
199+
{
200+
auto target = std::make_shared<Sprite>();
201+
ScriptBuilder builder(m_extension.get(), m_engine, target);
202+
203+
builder.addBlock("operator_equals");
204+
builder.addValueInput("OPERAND1", 5.4645);
205+
builder.addValueInput("OPERAND2", 12.486);
206+
builder.captureBlockReturnValue();
207+
208+
builder.addBlock("operator_equals");
209+
builder.addValueInput("OPERAND1", 153.25);
210+
builder.addValueInput("OPERAND2", 96.5);
211+
builder.captureBlockReturnValue();
212+
213+
builder.addBlock("operator_equals");
214+
builder.addValueInput("OPERAND1", 2.8465);
215+
builder.addValueInput("OPERAND2", 2.8465);
216+
builder.captureBlockReturnValue();
217+
218+
builder.build();
219+
builder.run();
220+
221+
List *valueList = builder.capturedValues();
222+
ValueData *values = valueList->data();
223+
ASSERT_EQ(valueList->size(), 3);
224+
ASSERT_EQ(Value(values[0]), false);
225+
ASSERT_EQ(Value(values[1]), false);
226+
ASSERT_EQ(Value(values[2]), true);
227+
}

0 commit comments

Comments
 (0)