@@ -46,7 +46,9 @@ TEST_CASE("abs works with ints", "[arduino-math]")
46
46
CHECK (abs (b) == b);
47
47
}
48
48
49
- bool compare_floats (float a, float b) {
49
+ template <typename T>
50
+ bool compare_floats (T a, T b) {
51
+ static_assert (std::is_floating_point<T>::value, " " );
50
52
return std::fabs (a - b) < std::numeric_limits<float >::epsilon ();
51
53
}
52
54
@@ -60,17 +62,17 @@ TEST_CASE("abs works with floats", "[arduino-math]")
60
62
CHECK (compare_floats (abs (b), b));
61
63
}
62
64
63
- TEST_CASE (" round works with floats " , " [arduino-math]" )
65
+ TEST_CASE (" round works with ints " , " [arduino-math]" )
64
66
{
65
- float a = 2.9 ;
66
- float b = 3.0 ;
67
- CHECK (TEST_MATH_IS_SAME (round (a), a ));
68
- CHECK (TEST_MATH_IS_SAME (round (b), b ));
69
- CHECK (compare_floats (round (a), b ));
70
- CHECK (compare_floats (round (b), b ));
67
+ int a = 5 ;
68
+ int b = 10 ;
69
+ CHECK (TEST_MATH_IS_SAME (round (a), std::round (a) ));
70
+ CHECK (TEST_MATH_IS_SAME (round (b), std::round (b) ));
71
+ CHECK (compare_floats (round (a), std::round (a) ));
72
+ CHECK (compare_floats (round (b), std::round (b) ));
71
73
}
72
74
73
- TEST_CASE (" round result is float " , " [arduino-math]" )
75
+ TEST_CASE (" round works with floats " , " [arduino-math]" )
74
76
{
75
77
float a = 2.9 ;
76
78
float b = 3.0 ;
0 commit comments