Skip to content

Commit

Permalink
test: Use FP utils to compare values in Result()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 6, 2020
1 parent 5fa8c39 commit 9dc8ab7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/utils/asserts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "execute.hpp"
#include <gmock/gmock.h>
#include <test/utils/floating_point_utils.hpp>
#include <iosfwd>

MATCHER(Traps, "") // NOLINT(readability-redundant-string-init)
Expand All @@ -23,10 +24,8 @@ MATCHER_P(Result, value, "") // NOLINT(readability-redundant-string-init)
if (arg.trapped || !arg.has_value)
return false;

if constexpr (std::is_same_v<value_type, float>)
return arg.value.f32 == value;
else if constexpr (std::is_same_v<value_type, double>)
return arg.value.f64 == value;
if constexpr (std::is_floating_point_v<value_type>)
return arg.value.template as<value_type>() == fizzy::test::FP{value};
else // always check 64 bit of result for all integers, including 32-bit results
return arg.value.i64 == static_cast<std::make_unsigned_t<value_type>>(value);
}
Expand Down

0 comments on commit 9dc8ab7

Please sign in to comment.