Skip to content

Commit

Permalink
test: Use FP utils in spectest runner
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 6, 2020
1 parent 5764d53 commit e34d942
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions test/spectests/spectests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "execute.hpp"
#include "parser.hpp"
#include <nlohmann/json.hpp>
#include <test/utils/floating_point_utils.hpp>
#include <test/utils/hex.hpp>
#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -58,22 +59,6 @@ fizzy::bytes load_wasm_file(const fs::path& json_file_path, std::string_view fil
std::istreambuf_iterator<char>{wasm_file}, std::istreambuf_iterator<char>{});
}

bool float_values_equal(fizzy::Value value1, fizzy::Value value2) noexcept
{
if (std::isnan(value1.as<float>()))
return value1.as<uint32_t>() == value2.as<uint32_t>(); // compare binary representations
else
return value1.as<float>() == value2.as<float>();
}

bool double_values_equal(fizzy::Value value1, fizzy::Value value2) noexcept
{
if (std::isnan(value1.as<double>()))
return value1.i64 == value2.i64; // compare binary representations
else
return value1.as<double>() == value2.as<double>();
}

struct test_settings
{
bool skip_validation = false;
Expand Down Expand Up @@ -482,9 +467,9 @@ class test_runner
if (value_type == "i32" || value_type == "i64")
is_equal = expected_value.i64 == actual_value.i64;
else if (value_type == "f32")
is_equal = float_values_equal(expected_value, actual_value);
is_equal = fizzy::test::FP{expected_value.f32} == actual_value.f32;
else if (value_type == "f64")
is_equal = double_values_equal(expected_value, actual_value);
is_equal = fizzy::test::FP{expected_value.f64} == actual_value.f64;
else
assert(false);

Expand Down

0 comments on commit e34d942

Please sign in to comment.