Expressions #7
@@ -152,6 +152,47 @@ TEST(VM, IntegerIntegerOperations)
|
|||||||
ASSERT_FLOAT_EQ(run("pushi 3\n pushi 2\n div").to_float(-1), 1.5f);
|
ASSERT_FLOAT_EQ(run("pushi 3\n pushi 2\n div").to_float(-1), 1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(VM, IntegerFloatOperations)
|
||||||
|
{
|
||||||
|
auto test_op = [](int32_t op1, float op2, std::string oper) -> VM {
|
||||||
|
return VM().load_bytecode(as::Assembler(std::format(R"(
|
||||||
|
.const
|
||||||
|
0: {}
|
||||||
|
.func 0
|
||||||
|
pushi {}
|
||||||
|
pushc {}
|
||||||
|
{}
|
||||||
|
ret
|
||||||
|
)", op2, op1, oper)).assemble()).call(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(test_op(2, 3.5f, "sum").to_float(-1), 5.5f);
|
||||||
|
/*
|
||||||
|
ASSERT_EQ(test_op(2, 3, "sub"), -1);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "mul"), 6);
|
||||||
|
ASSERT_EQ(test_op(20, 3, "idiv"), 6);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "eq"), 0);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "neq"), 1);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "lt"), 1);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "lte"), 1);
|
||||||
|
ASSERT_EQ(test_op(3, 3, "lte"), 1);
|
||||||
|
ASSERT_EQ(test_op(4, 3, "lte"), 0);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "gt"), 0);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "gte"), 0);
|
||||||
|
ASSERT_EQ(test_op(3, 3, "gte"), 1);
|
||||||
|
ASSERT_EQ(test_op(4, 3, "gte"), 1);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "and"), 2);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "or"), 3);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "xor"), 1);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "pow"), 8);
|
||||||
|
ASSERT_EQ(test_op(2, 3, "shl"), 16);
|
||||||
|
ASSERT_EQ(test_op(30, 2, "shr"), 7);
|
||||||
|
ASSERT_EQ(test_op(8, 3, "mod"), 2);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(run("pushi 3\n pushi 2\n div").to_float(-1), 1.5f);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user