MRaster examples 21.0.0.0
Image Processing Library
Loading...
Searching...
No Matches
utest_mjrmath.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file utest_ramCanvasTpl.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2022-08-24
7 @brief unit tests for ramCanvasTpl on 64-bit little endian hardware -- like ia64/x86_64.@EOL
8 @std C++20
9 @copyright
10 @parblock
11 Copyright (c) 2022, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 DAMAGE.
29 @endparblock
30*/
31/*******************************************************************************************************************************************************.H.E.**/
32/** @cond exj */
33
34#define BOOST_TEST_DYN_LINK
35#define BOOST_TEST_MODULE Main
36#include <boost/test/unit_test.hpp>
37
38#define BOOST_TEST_DYN_LINK
39#ifdef STAND_ALONE
40# define BOOST_TEST_MODULE Main
41#endif
42#include <boost/test/unit_test.hpp>
43
44#include "mjrmath.hpp"
45
46#if 0
47
48// |--------+----------------------------|
49// | | numberWrap |
50// | | mjr::math::ivl::wrapCO |
51// | | intClamp |
52// | | mjr::math::ivl::unit_clamp |
53// |--------+----------------------------|
54// | | mjr::math:linm::interpolate |
55// | | interpolate_degrees |
56// |--------+----------------------------|
57// | | intLinMap |
58// | | genLinMap |
59// | | unitTooIntLinMap |
60// |--------+----------------------------|
61// | | max3 |
62// | | min4 |
63// |--------+----------------------------|
64// | DIRECT | fmtInt |
65// | | fmtDbl |
66// |--------+----------------------------|
67// | | evalUniPoly |
68// | DIRECT | maxExpBiPoly |
69// | DIRECT | evalBiPoly |
70// |--------+----------------------------|
71
72////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73BOOST_AUTO_TEST_CASE(maxExpBiPoly) {
74 // normal cases
75 for(int i=2; i<=100; i++)
76 BOOST_TEST_CHECK(mjr::maxExpBiPoly((i+1)*(i+1)) == i);
77 // one too small to be a poly
78 for(int i=2; i<=100; i++)
79 BOOST_TEST_CHECK(mjr::maxExpBiPoly((i+1)*(i+1)-1) == -3);
80 // one too big to be a poly
81 for(int i=2; i<100; i++)
82 BOOST_TEST_CHECK(mjr::maxExpBiPoly((i+1)*(i+1)+1) == -3);
83 // too big to support
84 BOOST_TEST_CHECK(mjr::maxExpBiPoly((100+1)*(100+1)+1) == -1);
85 BOOST_TEST_CHECK(mjr::maxExpBiPoly((101+1)*(101+1)) == -1);
86 // too small to support
87 BOOST_TEST_CHECK(mjr::maxExpBiPoly(0) == -2);
88}
89
90////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
91BOOST_AUTO_TEST_CASE(evalBiPoly, * boost::unit_test::tolerance(0.00001)) {
92
93 std::vector<double> BiPoly01 {1, 2, 3, 4, 5, 6, 7, 8, 9};
94 std::vector<double> BiPoly02 {9, 8, 7, 6, 5, 4, 3, 2, 1};
95
96 std::vector<double> BiPoly03 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
97 std::vector<double> BiPoly04 {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
98
99 //------------------------------------------------------------------------------------------------------------------------------------------------------------
100
101 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly01, 0, 0) == 9);
102 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly01, 0, 1) == 24);
103 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly01, 1, 0) == 18);
104 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly01, 1, 1) == 45);
105 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly01, 2, 3) == 282);
106
107 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly02, 0, 0) == 1);
108 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly02, 0, 1) == 6);
109 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly02, 1, 0) == 12);
110 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly02, 1, 1) == 45);
111 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly02, 2, 3) == 628);
112
113 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly03, 0, 0) == 16);
114 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly03, 0, 1) == 58);
115 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly03, 1, 0) == 40);
116 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly03, 1, 1) == 136);
117 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly03, 2, 3) == 2630);
118
119 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly04, 0, 0) == 1);
120 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly04, 0, 1) == 10);
121 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly04, 1, 0) == 28);
122 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly04, 1, 1) == 136);
123 BOOST_TEST_CHECK(mjr::math::bply::eval(BiPoly04, 2, 3) == 7570);
124}
125
126////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127BOOST_AUTO_TEST_CASE(fmtInt) {
128
129 // Check default args
130 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10 ) == "10");
131 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4 ) == " 10");
132 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ' ) == " 10");
133 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 10 ) == " 10");
134 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 10, true) == " 10");
135
136 // dec
137 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 10, true) == "10");
138 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 10, true) == "10");
139 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 10, true) == "10");
140 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 10, true) == " 10");
141 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 10, true) == " 10");
142
143 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 10, true) == "10");
144 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 10, true) == "10");
145 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 10, true) == "10");
146 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 10, true) == "X10");
147 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 10, true) == "XX10");
148
149 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 10, false) == "10");
150 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 10, false) == "10");
151 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 10, false) == "10");
152 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 10, false) == "10 ");
153 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 10, false) == "10 ");
154
155 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 10, false) == "10");
156 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 10, false) == "10");
157 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 10, false) == "10");
158 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 10, false) == "10X");
159 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 10, false) == "10XX");
160
161 // hex
162 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 16, true) == "a");
163 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 16, true) == "a");
164 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 16, true) == " a");
165 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 16, true) == " a");
166 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 16, true) == " a");
167
168 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 16, true) == "a");
169 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 16, true) == "a");
170 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 16, true) == "Xa");
171 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 16, true) == "XXa");
172 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 16, true) == "XXXa");
173
174 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 16, false) == "a");
175 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 16, false) == "a");
176 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 16, false) == "a ");
177 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 16, false) == "a ");
178 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 16, false) == "a ");
179
180 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 16, false) == "a");
181 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 16, false) == "a");
182 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 16, false) == "aX");
183 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 16, false) == "aXX");
184 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 16, false) == "aXXX");
185
186 // oct
187 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 8, true) == "12");
188 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 8, true) == "12");
189 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 8, true) == "12");
190 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 8, true) == " 12");
191 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 8, true) == " 12");
192
193 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 8, true) == "12");
194 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 8, true) == "12");
195 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 8, true) == "12");
196 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 8, true) == "X12");
197 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 8, true) == "XX12");
198
199 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, ' ', 8, false) == "12");
200 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, ' ', 8, false) == "12");
201 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, ' ', 8, false) == "12");
202 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, ' ', 8, false) == "12 ");
203 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, ' ', 8, false) == "12 ");
204
205 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 0, 'X', 8, false) == "12");
206 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 1, 'X', 8, false) == "12");
207 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 2, 'X', 8, false) == "12");
208 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 3, 'X', 8, false) == "12X");
209 BOOST_TEST_CHECK(mjr::math::str::fmt_int(10, 4, 'X', 8, false) == "12XX");
210}
211
212#endif
213/** @endcond */
214
215