1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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 DAMAGE.
---------------------------------------------------------------------------
*/
#include "UnitTestPCH.h"
#include <assimp/fast_atof.h>
namespace {
template <typename Real>
bool IsNan(Real x) {
return x != x;
}
template <typename Real>
bool IsInf(Real x) {
return std::abs(x) == std::numeric_limits<Real>::infinity();
}
} // Namespace
class FastAtofTest : public ::testing::Test
{
protected:
template <typename Real, typename AtofFunc>
static void RunTest(AtofFunc atof_func)
{
const Real kEps = 1e-5f;
#define TEST_CASE(NUM) EXPECT_NEAR(static_cast<Real>(NUM), atof_func(#NUM), kEps)
#define TEST_CASE_NAN(NUM) EXPECT_TRUE(IsNan(atof_func(#NUM)))
#define TEST_CASE_INF(NUM) EXPECT_TRUE(IsInf(atof_func(#NUM)))
TEST_CASE(0);
TEST_CASE(1.354);
TEST_CASE(1054E-3);
TEST_CASE(-1054E-3);
TEST_CASE(-10.54E30);
TEST_CASE(-345554.54e-5);
TEST_CASE(-34555.534954e-5);
TEST_CASE(-34555.534954e-5);
TEST_CASE(549067);
TEST_CASE(567);
TEST_CASE(446);
TEST_CASE(7);
TEST_CASE(73);
TEST_CASE(256);
TEST_CASE(5676);
TEST_CASE(3);
TEST_CASE(738);
TEST_CASE(684);
TEST_CASE(26);
TEST_CASE(673.678e-56);
TEST_CASE(53);
TEST_CASE(67);
TEST_CASE(684);
TEST_CASE(-5437E24);
TEST_CASE(8);
TEST_CASE(84);
TEST_CASE(3);
TEST_CASE(56733.68);
TEST_CASE(786);
TEST_CASE(6478);
TEST_CASE(34563.65683598734);
TEST_CASE(5673);
TEST_CASE(784e-3);
TEST_CASE(8678);
TEST_CASE(46784);
TEST_CASE(-54.0888e-6);
TEST_CASE(100000e10);
TEST_CASE(1e-307);
TEST_CASE(0.000001e-301);
TEST_CASE(0.0000001e-300);
TEST_CASE(0.00000001e-299);
TEST_CASE(1000000e-313);
TEST_CASE(10000000e-314);
TEST_CASE(100000000e-315);
TEST_CASE(12.345);
TEST_CASE(12.345e19);
TEST_CASE(-.1e+9);
TEST_CASE(.125);
TEST_CASE(1e20);
TEST_CASE(0e-19);
TEST_CASE(400012);
TEST_CASE(5.9e-76);
TEST_CASE_INF(inf);
TEST_CASE_INF(inf);
TEST_CASE_INF(infinity);
TEST_CASE_INF(Inf);
TEST_CASE_INF(-Inf);
TEST_CASE_INF(+InFiNiTy);
TEST_CASE_NAN(NAN);
TEST_CASE_NAN(NaN);
TEST_CASE_NAN(nan);
EXPECT_EQ(static_cast<Real>(6), atof_func("006"));
EXPECT_EQ(static_cast<Real>(5.3), atof_func("5.300 "));
/* Failing Cases:
EXPECT_EQ(static_cast<Real>(6), atof_func(" 006"));
EXPECT_EQ(static_cast<Real>(5.3), atof_func(" 5.300 "));
TEST_CASE(-10.54E45);
TEST_CASE(0x0A);
TEST_CASE(0xA0);
TEST_CASE(0x1p1023);
TEST_CASE(0x1000p1011);
TEST_CASE(0x1p1020);
TEST_CASE(0x0.00001p1040);
TEST_CASE(0x1p-1021);
TEST_CASE(0x1000p-1033);
TEST_CASE(0x10000p-1037);
TEST_CASE(0x0.001p-1009);
TEST_CASE(0x0.0001p-1005);
TEST_CASE(0x1.4p+3);
TEST_CASE(0xAp0);
TEST_CASE(0x0Ap0);
TEST_CASE(0x0.A0p8);
TEST_CASE(0x0.50p9);
TEST_CASE(0x0.28p10);
TEST_CASE(0x0.14p11);
TEST_CASE(0x0.0A0p12);
TEST_CASE(0x0.050p13);
TEST_CASE(0x0.028p14);
TEST_CASE(0x0.014p15);
TEST_CASE(0x00.00A0p16);
TEST_CASE(0x00.0050p17);
TEST_CASE(0x00.0028p18);
TEST_CASE(0x00.0014p19);
TEST_CASE(0x1p-1023);
TEST_CASE(0x0.8p-1022);
TEST_CASE(0x80000Ap-23);
TEST_CASE(0x100000000000008p0);
TEST_CASE(0x100000000000008.p0);
TEST_CASE(0x100000000000008.00p0);
TEST_CASE(0x10000000000000800p0);
TEST_CASE(0x10000000000000801p0)
*/
#undef TEST_CASE
#undef TEST_CASE_NAN
#undef TEST_CASE_INF
}
};
struct FastAtofWrapper {
ai_real operator()(const char* str) { return Assimp::fast_atof(str); }
};
TEST_F(FastAtofTest, FastAtof)
{
RunTest<ai_real>(FastAtofWrapper());
}
|