@@ -65,6 +65,7 @@ TEST_F(PenBlocksTest, RegisterBlocks)
6565 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " pen_penDown" 
6666 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " pen_penUp" 
6767 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " pen_changePenSizeBy" 
68+  EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " pen_setPenSizeTo" 
6869
6970 //  Inputs
7071 EXPECT_CALL (m_engineMock, addInput (m_section.get (), " SIZE" 
@@ -264,3 +265,68 @@ TEST_F(PenBlocksTest, ChangePenSizeByImpl)
264265 ASSERT_EQ (vm.registerCount (), 0 );
265266 ASSERT_EQ (model.penAttributes ().diameter , 1 );
266267}
268+ 
269+ TEST_F (PenBlocksTest, SetPenSizeTo)
270+ {
271+  Compiler compiler (&m_engineMock);
272+ 
273+  //  set pen size to (51.46)
274+  auto  block1 = std::make_shared<Block>(" a" " pen_setPenSizeTo" 
275+  addValueInput (block1, " SIZE" 51.46 );
276+ 
277+  //  change pen size by (null block)
278+  auto  block2 = std::make_shared<Block>(" b" " pen_setPenSizeTo" 
279+  addObscuredInput (block2, " SIZE" createNullBlock (" c" 
280+ 
281+  compiler.init ();
282+ 
283+  EXPECT_CALL (m_engineMock, functionIndex (&PenBlocks::setPenSizeTo)).WillOnce (Return (2 ));
284+  compiler.setBlock (block1);
285+  PenBlocks::compileSetPenSizeTo (&compiler);
286+ 
287+  EXPECT_CALL (m_engineMock, functionIndex (&PenBlocks::setPenSizeTo)).WillOnce (Return (2 ));
288+  compiler.setBlock (block2);
289+  PenBlocks::compileSetPenSizeTo (&compiler);
290+ 
291+  compiler.end ();
292+ 
293+  ASSERT_EQ (compiler.bytecode (), std::vector<unsigned  int >({ vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 2 , vm::OP_NULL, vm::OP_EXEC, 2 , vm::OP_HALT }));
294+  ASSERT_EQ (compiler.constValues ().size (), 1 );
295+  ASSERT_EQ (compiler.constValues ()[0 ].toDouble (), 51.46 );
296+  ASSERT_TRUE (compiler.variables ().empty ());
297+  ASSERT_TRUE (compiler.lists ().empty ());
298+ }
299+ 
300+ TEST_F (PenBlocksTest, SetPenSizeToImpl)
301+ {
302+  static  unsigned  int  bytecode1[] = { vm::OP_START, vm::OP_CONST, 0 , vm::OP_EXEC, 0 , vm::OP_HALT };
303+  static  unsigned  int  bytecode2[] = { vm::OP_START, vm::OP_CONST, 1 , vm::OP_EXEC, 0 , vm::OP_HALT };
304+  static  unsigned  int  bytecode3[] = { vm::OP_START, vm::OP_CONST, 2 , vm::OP_EXEC, 0 , vm::OP_HALT };
305+  static  BlockFunc functions[] = { &PenBlocks::setPenSizeTo };
306+  static  Value constValues[] = { 511.5 , -650.08 , 1500  };
307+ 
308+  SpriteModel model;
309+  Sprite sprite;
310+  sprite.setInterface (&model);
311+ 
312+  VirtualMachine vm (&sprite, &m_engineMock, nullptr );
313+  vm.setBytecode (bytecode1);
314+  vm.setFunctions (functions);
315+  vm.setConstValues (constValues);
316+ 
317+  vm.run ();
318+  ASSERT_EQ (vm.registerCount (), 0 );
319+  ASSERT_EQ (model.penAttributes ().diameter , 511.5 );
320+ 
321+  vm.reset ();
322+  vm.setBytecode (bytecode2);
323+  vm.run ();
324+  ASSERT_EQ (vm.registerCount (), 0 );
325+  ASSERT_EQ (model.penAttributes ().diameter , 1 );
326+ 
327+  vm.reset ();
328+  vm.setBytecode (bytecode3);
329+  vm.run ();
330+  ASSERT_EQ (vm.registerCount (), 0 );
331+  ASSERT_EQ (model.penAttributes ().diameter , 1200 );
332+ }
0 commit comments