HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
polynomial_tests.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5// Copyright 2019 Pokitec
6// All rights reserved.
7
8#include "ttauri/polynomial.hpp"
9#include <gtest/gtest.h>
10#include <iostream>
11#include <string>
12
13template<typename T, typename U, int N>
14double maxAbsDiff(tt::results<T,N> const &lhs, tt::results<U,N> const &rhs) {
15 if (lhs.count != rhs.count) {
17 }
18
19 double maxDiff = 0.0;
20 assert(lhs.count <= lhs.maxCount);
21 for (ptrdiff_t i = 0; i < lhs.count; i++) {
22 ttlet diff = std::abs(lhs.value[i] - rhs.value[i]);
23 maxDiff = std::max(maxDiff, diff);
24 }
25 return maxDiff;
26}
27
28template<typename T, typename U, int N>
29testing::AssertionResult ResultsNearPredFormat(const char* expr1,
30 const char* expr2,
31 const char* abs_error_expr,
34 double abs_error) {
35 ttlet diff = maxAbsDiff(val1, val2);
36 if (diff <= abs_error) return testing::AssertionSuccess();
37
38 return testing::AssertionFailure()
39 << "The difference between " << expr1 << " and " << expr2
40 << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
41 << expr1 << " evaluates to " << val1 << ",\n"
42 << expr2 << " evaluates to " << val2 << ", and\n"
43 << abs_error_expr << " evaluates to " << abs_error << ".";
44}
45
46#define ASSERT_RESULTS_NEAR(val1, val2, abs_error)\
47 ASSERT_PRED_FORMAT3(ResultsNearPredFormat, val1, val2, abs_error)
48
49#define ASSERT_RESULTS(val1, val2) ASSERT_RESULTS_NEAR(val1, val2, 0.000001)
50
51namespace tt {
52using results1 = tt::results<double,1>;
53using results2 = tt::results<double,2>;
54using results3 = tt::results<double,3>;
55}
Definition polynomial.hpp:14
T infinity(T... args)
T max(T... args)