.
This commit is contained in:
@@ -93,7 +93,7 @@ static int init_ = []() {
|
||||
|
||||
Value binary_operation(Value const& a, Value const& b, BinaryOperationType op)
|
||||
{
|
||||
return binary_ops[(size_t) op][(size_t) a.type()][(size_t) b.type()](a, b);
|
||||
return binary_ops[(size_t) op][(size_t) b.type()][(size_t) a.type()](a, b);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -154,19 +154,25 @@ TEST(VM, IntegerIntegerOperations)
|
||||
|
||||
TEST(VM, IntegerFloatOperations)
|
||||
{
|
||||
auto test_op = [](int32_t op1, float op2, std::string oper) -> VM {
|
||||
auto test_op = [](int op1, std::string const& op2, std::string oper) -> VM {
|
||||
return VM().load_bytecode(as::Assembler(std::format(R"(
|
||||
.const
|
||||
0: {}
|
||||
.func 0
|
||||
pushi {}
|
||||
pushc {}
|
||||
pushc 0
|
||||
{}
|
||||
ret
|
||||
)", op2, op1, oper)).assemble()).call(0);
|
||||
};
|
||||
|
||||
ASSERT_FLOAT_EQ(test_op(2, 3.5f, "sum").to_float(-1), 5.5f);
|
||||
ASSERT_FLOAT_EQ(test_op(2, "3.5", "sum").to_float(-1), 5.5f);
|
||||
ASSERT_FLOAT_EQ(test_op(2, "3.5", "sub").to_float(-1), -1.5f);
|
||||
ASSERT_FLOAT_EQ(test_op(2, "3.5", "mul").to_float(-1), 7.f);
|
||||
ASSERT_FLOAT_EQ(test_op(20, "3.5", "idiv").to_integer(-1), 6);
|
||||
ASSERT_FLOAT_EQ(test_op(20, "3.5", "div").to_float(-1), 5.7142859);
|
||||
ASSERT_FLOAT_EQ(test_op(3, "3.5", "eq").to_integer(-1), 0);
|
||||
ASSERT_FLOAT_EQ(test_op(3, "3.0", "eq").to_integer(-1), 1);
|
||||
/*
|
||||
ASSERT_EQ(test_op(2, 3, "sub"), -1);
|
||||
ASSERT_EQ(test_op(2, 3, "mul"), 6);
|
||||
|
||||
Reference in New Issue
Block a user