| 3579 | |
| 3580 | template<typename T> |
| 3581 | struct ApproxMatcher : MatcherBase<std::vector<T>> { |
| 3582 | |
| 3583 | ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {} |
| 3584 | |
| 3585 | bool match(std::vector<T> const &v) const override { |
| 3586 | if (m_comparator.size() != v.size()) |
| 3587 | return false; |
| 3588 | for (std::size_t i = 0; i < v.size(); ++i) |
| 3589 | if (m_comparator[i] != approx(v[i])) |
| 3590 | return false; |
| 3591 | return true; |
| 3592 | } |
| 3593 | std::string describe() const override { |
| 3594 | return "is approx: " + ::Catch::Detail::stringify( m_comparator ); |
| 3595 | } |
| 3596 | template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> |
| 3597 | ApproxMatcher& epsilon( T const& newEpsilon ) { |
| 3598 | approx.epsilon(newEpsilon); |
| 3599 | return *this; |
| 3600 | } |
| 3601 | template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> |
| 3602 | ApproxMatcher& margin( T const& newMargin ) { |
| 3603 | approx.margin(newMargin); |
| 3604 | return *this; |
| 3605 | } |
| 3606 | template <typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> |
| 3607 | ApproxMatcher& scale( T const& newScale ) { |
| 3608 | approx.scale(newScale); |
| 3609 | return *this; |
| 3610 | } |
| 3611 | |
| 3612 | std::vector<T> const& m_comparator; |
| 3613 | mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); |
| 3614 | }; |
| 3615 | |
| 3616 | template<typename T> |
| 3617 | struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> { |