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#pragma once
6
7#include "ttauri/polynomial.hpp"
8#include <gtest/gtest.h>
9#include <iostream>
10#include <string>
11
12template<typename T, typename U, int N>
13double maxAbsDiff(tt::results<T,N> const &lhs, tt::results<U,N> const &rhs) {
14 if (lhs.count != rhs.count) {
16 }
17
18 double maxDiff = 0.0;
19 assert(lhs.count <= lhs.maxCount);
20 for (ptrdiff_t i = 0; i < lhs.count; i++) {
21 ttlet diff = std::abs(lhs.value[i] - rhs.value[i]);
22 maxDiff = std::max(maxDiff, diff);
23 }
24 return maxDiff;
25}
26
27template<typename T, typename U, int N>
28testing::AssertionResult ResultsNearPredFormat(const char* expr1,
29 const char* expr2,
30 const char* abs_error_expr,
33 double abs_error) {
34 ttlet diff = maxAbsDiff(val1, val2);
35 if (diff <= abs_error) return testing::AssertionSuccess();
36
37 return testing::AssertionFailure()
38 << "The difference between " << expr1 << " and " << expr2
39 << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
40 << expr1 << " evaluates to " << val1 << ",\n"
41 << expr2 << " evaluates to " << val2 << ", and\n"
42 << abs_error_expr << " evaluates to " << abs_error << ".";
43}
44
45#define ASSERT_RESULTS_NEAR(val1, val2, abs_error)\
46 ASSERT_PRED_FORMAT3(ResultsNearPredFormat, val1, val2, abs_error)
47
48#define ASSERT_RESULTS(val1, val2) ASSERT_RESULTS_NEAR(val1, val2, 0.000001)
49
50namespace tt {
51using results1 = tt::results<double,1>;
52using results2 = tt::results<double,2>;
53using results3 = tt::results<double,3>;
54}
Definition polynomial.hpp:14
T infinity(T... args)
T max(T... args)