cmoon::test::assert_almost_equal


Defined in module <cmoon.test>


template<cmoon::arithmetic T, cmoon::arithmetic F>
void assert_almost_equal(const T& first, const F& second, const std::common_type_t<T, F>& delta, std::string_view message = "", const std::source_location& location = std::source_location::current());


(1)

Throws an assert_exception if the difference between first and second are greater than delta.

Parameters

first - First object in the comparison
second - Second object in the comparison
delta - Minimum difference to test between two objects
message - Extra information to be added to the error message
location - Information about where in the file this assertion was ran

Return value

(none)

Example



import cmoon.test;

class example_test : public cmoon::test::test_case
{
    public:
        example_test()
            : cmoon::test::test_case{"example test"} {}

        void operator()() override
        {
            constexpr double expected {5.0};
            constexpr double value {5.0};

            cmoon::test::assert_almost_equal(value, expected, 0.0001);
        }
};