Skip to content

Commit 3a39a57

Browse files
committed
Implement operator_lt
1 parent b678de0 commit 3a39a57

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
@@ -25,6 +25,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
2525
engine->addCompileFunction(this, "operator_multiply", &compileMultiply);
2626
engine->addCompileFunction(this, "operator_divide", &compileDivide);
2727
engine->addCompileFunction(this, "operator_random", &compileRandom);
28+
engine->addCompileFunction(this, "operator_lt", &compileLt);
2829
}
2930

3031
CompilerValue *OperatorBlocks::compileAdd(Compiler *compiler)
@@ -53,3 +54,8 @@ CompilerValue *OperatorBlocks::compileRandom(Compiler *compiler)
5354
auto to = compiler->addInput("TO");
5455
return compiler->createRandom(from, to);
5556
}
57+
58+
CompilerValue *OperatorBlocks::compileLt(Compiler *compiler)
59+
{
60+
return compiler->createCmpLT(compiler->addInput("OPERAND1"), compiler->addInput("OPERAND2"));
61+
}

src/dev/blocks/operatorblocks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class OperatorBlocks : public IExtension
2323
static CompilerValue *compileMultiply(Compiler *compiler);
2424
static CompilerValue *compileDivide(Compiler *compiler);
2525
static CompilerValue *compileRandom(Compiler *compiler);
26+
static CompilerValue *compileLt(Compiler *compiler);
2627
};
2728

2829
} // namespace libscratchcpp

test/dev/blocks/operator_blocks_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,34 @@ TEST_F(OperatorBlocksTest, Random)
163163
code->run(ctx.get());
164164
ASSERT_EQ(testing::internal::GetCapturedStdout(), expected);
165165
}
166+
167+
TEST_F(OperatorBlocksTest, Lt)
168+
{
169+
auto target = std::make_shared<Sprite>();
170+
ScriptBuilder builder(m_extension.get(), m_engine, target);
171+
172+
builder.addBlock("operator_lt");
173+
builder.addValueInput("OPERAND1", 5.4645);
174+
builder.addValueInput("OPERAND2", 12.486);
175+
builder.captureBlockReturnValue();
176+
177+
builder.addBlock("operator_lt");
178+
builder.addValueInput("OPERAND1", 153.25);
179+
builder.addValueInput("OPERAND2", 96.5);
180+
builder.captureBlockReturnValue();
181+
182+
builder.addBlock("operator_lt");
183+
builder.addValueInput("OPERAND1", 2.8465);
184+
builder.addValueInput("OPERAND2", 2.8465);
185+
builder.captureBlockReturnValue();
186+
187+
builder.build();
188+
builder.run();
189+
190+
List *valueList = builder.capturedValues();
191+
ValueData *values = valueList->data();
192+
ASSERT_EQ(valueList->size(), 3);
193+
ASSERT_EQ(Value(values[0]), true);
194+
ASSERT_EQ(Value(values[1]), false);
195+
ASSERT_EQ(Value(values[2]), false);
196+
}

0 commit comments

Comments
 (0)