Skip to content

Commit d3ef6a1

Browse files
committed
Implement operator_gt
1 parent c040d5e commit d3ef6a1

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
@@ -27,6 +27,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2727
engine->addCompileFunction(this, "operator_random", &compileRandom);
2828
engine->addCompileFunction(this, "operator_lt", &compileLt);
2929
engine->addCompileFunction(this, "operator_equals", &compileEquals);
30+
engine->addCompileFunction(this, "operator_gt", &compileGt);
3031
}
3132

3233
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -65,3 +66,8 @@ CompilerValue *OperatorBlocks::compileEquals(Compiler *compiler)
6566
{
6667
return compiler->createCmpEQ(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
6768
}
69+
70+
CompilerValue *OperatorBlocks::compileGt(Compiler *compiler)
71+
{
72+
return compiler->createCmpGT(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
73+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class OperatorBlocks : public IExtension
2525
static CompilerValue *compileRandom(Compiler *compiler);
2626
static CompilerValue *compileLt(Compiler *compiler);
2727
static CompilerValue *compileEquals(Compiler *compiler);
28+
static CompilerValue *compileGt(Compiler *compiler);
2829
};
2930

3031
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,34 @@ TEST_F(OperatorBlocksTest, Equals)
225225
ASSERT_EQ(Value(values[1]), false);
226226
ASSERT_EQ(Value(values[2]), true);
227227
}
228+
229+
TEST_F(OperatorBlocksTest, Gt)
230+
{
231+
auto target = std::make_shared<Sprite>();
232+
ScriptBuilder builder(m_extension.get(), m_engine, target);
233+
234+
builder.addBlock("operator_gt");
235+
builder.addValueInput("OPERAND1", 5.4645);
236+
builder.addValueInput("OPERAND2", 12.486);
237+
builder.captureBlockReturnValue();
238+
239+
builder.addBlock("operator_gt");
240+
builder.addValueInput("OPERAND1", 153.25);
241+
builder.addValueInput("OPERAND2", 96.5);
242+
builder.captureBlockReturnValue();
243+
244+
builder.addBlock("operator_gt");
245+
builder.addValueInput("OPERAND1", 2.8465);
246+
builder.addValueInput("OPERAND2", 2.8465);
247+
builder.captureBlockReturnValue();
248+
249+
builder.build();
250+
builder.run();
251+
252+
List *valueList = builder.capturedValues();
253+
ValueData *values = valueList->data();
254+
ASSERT_EQ(valueList->size(), 3);
255+
ASSERT_EQ(Value(values[0]), false);
256+
ASSERT_EQ(Value(values[1]), true);
257+
ASSERT_EQ(Value(values[2]), false);
258+
}

0 commit comments

Comments
 (0)