@@ -362,6 +362,57 @@ TEST(VirtualMachineTest, OP_MOD)
362362 ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), 1.5 );
363363}
364364
365+ TEST (VirtualMachineTest, OP_RANDOM)
366+ {
367+ static unsigned int bytecode1[] = { OP_START, OP_CONST, 0 , OP_CONST, 1 , OP_RANDOM, OP_HALT };
368+ static unsigned int bytecode2[] = { OP_START, OP_CONST, 1 , OP_CONST, 2 , OP_RANDOM, OP_HALT };
369+ static unsigned int bytecode3[] = { OP_START, OP_CONST, 3 , OP_CONST, 0 , OP_RANDOM, OP_HALT };
370+ static unsigned int bytecode4[] = { OP_START, OP_CONST, 2 , OP_CONST, 3 , OP_RANDOM, OP_HALT };
371+ static Value constValues[] = { -45 , 12 , 6.05 , -78.686 };
372+
373+ VirtualMachinePrivate vm (nullptr , nullptr , nullptr , nullptr );
374+ vm.constValues = constValues;
375+
376+ RandomGeneratorMock rng;
377+ vm.rng = &rng;
378+
379+ EXPECT_CALL (rng, randint (-45 , 12 )).WillOnce (Return (-18 ));
380+ vm.bytecode = bytecode1;
381+ vm.pos = bytecode1;
382+ vm.regCount = 0 ;
383+ vm.run (vm.pos );
384+
385+ ASSERT_EQ (vm.regCount , 1 );
386+ ASSERT_EQ (vm.regs [vm.regCount - 1 ]->toDouble (), -18 );
387+
388+ EXPECT_CALL (rng, randintDouble (12 , 6.05 )).WillOnce (Return (3.486789 ));
389+ vm.bytecode = bytecode2;
390+ vm.pos = bytecode2;
391+ vm.regCount = 0 ;
392+ vm.run (vm.pos );
393+
394+ ASSERT_EQ (vm.regCount , 1 );
395+ ASSERT_EQ (vm.regs [vm.regCount - 1 ]->toDouble (), 3.486789 );
396+
397+ EXPECT_CALL (rng, randintDouble (-78.686 , -45 )).WillOnce (Return (-59.468873 ));
398+ vm.bytecode = bytecode3;
399+ vm.pos = bytecode3;
400+ vm.regCount = 0 ;
401+ vm.run (vm.pos );
402+
403+ ASSERT_EQ (vm.regCount , 1 );
404+ ASSERT_EQ (vm.regs [vm.regCount - 1 ]->toDouble (), -59.468873 );
405+
406+ EXPECT_CALL (rng, randintDouble (6.05 , -78.686 )).WillOnce (Return (-28.648764 ));
407+ vm.bytecode = bytecode4;
408+ vm.pos = bytecode4;
409+ vm.regCount = 0 ;
410+ vm.run (vm.pos );
411+
412+ ASSERT_EQ (vm.regCount , 1 );
413+ ASSERT_EQ (vm.regs [vm.regCount - 1 ]->toDouble (), -28.648764 );
414+ }
415+
365416TEST (VirtualMachineTest, OP_ROUND)
366417{
367418 static unsigned int bytecode[] = {
0 commit comments