@@ -54,10 +54,12 @@ TEST_F(MotionBlocksTest, RegisterBlocks)
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));
5656 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " motion_turnleft" , &MotionBlocks::compileTurnLeft));
57+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " motion_pointindirection" , &MotionBlocks::compilePointInDirection));
5758
5859 // Inputs
5960 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " STEPS" , MotionBlocks::STEPS));
6061 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " DEGREES" , MotionBlocks::DEGREES));
62+ EXPECT_CALL (m_engineMock, addInput (m_section.get (), " DIRECTION" , MotionBlocks::DIRECTION));
6163
6264 m_section->registerBlocks (&m_engineMock);
6365}
@@ -181,3 +183,42 @@ TEST_F(MotionBlocksTest, TurnLeftImpl)
181183 ASSERT_EQ (vm.registerCount (), 0 );
182184 ASSERT_EQ (std::round (sprite.direction () * 100 ) / 100 , 112.32 );
183185}
186+
187+ TEST_F (MotionBlocksTest, PointInDirection)
188+ {
189+ Compiler compiler (&m_engineMock);
190+
191+ // point in direction (-60.5)
192+ auto block = std::make_shared<Block>(" a" , " motion_pointindirection" );
193+ addValueInput (block, " DIRECTION" , MotionBlocks::DIRECTION, -60.5 );
194+
195+ EXPECT_CALL (m_engineMock, functionIndex (&MotionBlocks::pointInDirection)).WillOnce (Return (0 ));
196+
197+ compiler.init ();
198+ compiler.setBlock (block);
199+ MotionBlocks::compilePointInDirection (&compiler);
200+ compiler.end ();
201+
202+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT }));
203+ ASSERT_EQ (compiler.constValues ().size (), 1 );
204+ ASSERT_EQ (compiler.constValues ()[0 ].toDouble (), -60.5 );
205+ }
206+
207+ TEST_F (MotionBlocksTest, PointInDirectionImpl)
208+ {
209+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
210+ static BlockFunc functions[] = { &MotionBlocks::pointInDirection };
211+ static Value constValues[] = { -60.5 };
212+
213+ Sprite sprite;
214+ sprite.setDirection (50.02 );
215+
216+ VirtualMachine vm (&sprite, nullptr , nullptr );
217+ vm.setBytecode (bytecode);
218+ vm.setFunctions (functions);
219+ vm.setConstValues (constValues);
220+ vm.run ();
221+
222+ ASSERT_EQ (vm.registerCount (), 0 );
223+ ASSERT_EQ (sprite.direction (), -60.5 );
224+ }
0 commit comments