@@ -53,6 +53,7 @@ TEST_F(MotionBlocksTest, RegisterBlocks)
5353 // Blocks
5454 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " motion_movesteps" , &MotionBlocks::compileMoveSteps));
5555 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " motion_turnright" , &MotionBlocks::compileTurnRight));
56+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " motion_turnleft" , &MotionBlocks::compileTurnLeft));
5657
5758 // Inputs
5859 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " STEPS" , MotionBlocks::STEPS));
@@ -141,3 +142,42 @@ TEST_F(MotionBlocksTest, TurnRightImpl)
141142 ASSERT_EQ (vm.registerCount (), 0 );
142143 ASSERT_EQ (std::round (sprite.direction () * 100 ) / 100 , 136.42 );
143144}
145+
146+ TEST_F (MotionBlocksTest, TurnLeft)
147+ {
148+ Compiler compiler (&m_engineMock);
149+
150+ // turn left (12.05) degrees
151+ auto block = std::make_shared<Block>(" a" , " motion_turnleft" );
152+ addValueInput (block, " DEGREES" , MotionBlocks::DEGREES, 12.05 );
153+
154+ EXPECT_CALL (m_engineMock, functionIndex (&MotionBlocks::turnLeft)).WillOnce (Return (0 ));
155+
156+ compiler.init ();
157+ compiler.setBlock (block);
158+ MotionBlocks::compileTurnLeft (&compiler);
159+ compiler.end ();
160+
161+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT }));
162+ ASSERT_EQ (compiler.constValues ().size (), 1 );
163+ ASSERT_EQ (compiler.constValues ()[0 ].toDouble (), 12.05 );
164+ }
165+
166+ TEST_F (MotionBlocksTest, TurnLeftImpl)
167+ {
168+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
169+ static BlockFunc functions[] = { &MotionBlocks::turnLeft };
170+ static Value constValues[] = { 12.05 };
171+
172+ Sprite sprite;
173+ sprite.setDirection (124.37 );
174+
175+ VirtualMachine vm (&sprite, nullptr , nullptr );
176+ vm.setBytecode (bytecode);
177+ vm.setFunctions (functions);
178+ vm.setConstValues (constValues);
179+ vm.run ();
180+
181+ ASSERT_EQ (vm.registerCount (), 0 );
182+ ASSERT_EQ (std::round (sprite.direction () * 100 ) / 100 , 112.32 );
183+ }
0 commit comments