Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 330 lines (294 sloc) 15.221 kb
97f5380 added testing for mathlib
Daniel Marjamäki authored
1 /*
2 * Cppcheck - A tool for static C/C++ code analysis
8cae17f @aggro80 Update year to 2012
aggro80 authored
3 * Copyright (C) 2007-2012 Daniel Marjamäki and Cppcheck team.
97f5380 added testing for mathlib
Daniel Marjamäki authored
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
fdde218 @aggro80 Fix GPL comments in all files. ">." was missing from the end.
aggro80 authored
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
97f5380 added testing for mathlib
Daniel Marjamäki authored
17 */
18
19
20
09859c1 @danmar refactoring the folder structure
authored
21 #include "mathlib.h"
97f5380 added testing for mathlib
Daniel Marjamäki authored
22 #include "testsuite.h"
23
6f8e42a @danmar changed the astyle formatting flags
authored
24 class TestMathLib : public TestFixture {
97f5380 added testing for mathlib
Daniel Marjamäki authored
25 public:
26 TestMathLib() : TestFixture("TestMathLib")
27 { }
28
29 private:
30
6f8e42a @danmar changed the astyle formatting flags
authored
31 void run() {
97f5380 added testing for mathlib
Daniel Marjamäki authored
32 TEST_CASE(calculate);
7be01da @orbitcowboy fixed ticket 3693. Added modulus operator to Mathlib + unittests. Add…
orbitcowboy authored
33 TEST_CASE(calculate1);
7803466 testing mathlib: Test that conversion to numbers work
Daniel Marjamäki authored
34 TEST_CASE(convert);
8ab26e8 @aggro80 Don't warn about division by zero if zero if floating point number.
aggro80 authored
35 TEST_CASE(isint);
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
36 TEST_CASE(isnegative);
37 TEST_CASE(isfloat);
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
38 TEST_CASE(isGreater)
39 TEST_CASE(isGreaterEqual)
40 TEST_CASE(isEqual)
41 TEST_CASE(isNotEqual)
42 TEST_CASE(isLess)
43 TEST_CASE(isLessEqual)
44 }
45
6f8e42a @danmar changed the astyle formatting flags
authored
46 void isGreater() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
47 ASSERT_EQUALS(true , MathLib::isGreater("1.0", "0.001"));
48 ASSERT_EQUALS(false, MathLib::isGreater("-1.0", "0.001"));
49 }
50
6f8e42a @danmar changed the astyle formatting flags
authored
51 void isGreaterEqual() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
52 ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.00", "1.0"));
53 ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.001", "1.0"));
54 ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.0", "0.001"));
55 ASSERT_EQUALS(false, MathLib::isGreaterEqual("-1.0", "0.001"));
56 }
57
6f8e42a @danmar changed the astyle formatting flags
authored
58 void isEqual() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
59 ASSERT_EQUALS(true , MathLib::isEqual("1.0", "1.0"));
60 ASSERT_EQUALS(false , MathLib::isEqual("1.", "1.01"));
f441a95 mathlib: fixed #2950: comparison of floating point values
Ettl Martin authored
61 ASSERT_EQUALS(true , MathLib::isEqual("0.1","1.0E-1"));
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
62 }
63
6f8e42a @danmar changed the astyle formatting flags
authored
64 void isNotEqual() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
65 ASSERT_EQUALS(false , MathLib::isNotEqual("1.0", "1.0"));
66 ASSERT_EQUALS(true , MathLib::isNotEqual("1.", "1.01"));
67 }
68
6f8e42a @danmar changed the astyle formatting flags
authored
69 void isLess() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
70 ASSERT_EQUALS(false , MathLib::isLess("1.0", "0.001"));
71 ASSERT_EQUALS(true , MathLib::isLess("-1.0", "0.001"));
72 }
73
6f8e42a @danmar changed the astyle formatting flags
authored
74 void isLessEqual() {
80ed0b2 testmathlib: improved testcoverage of mathlib
Ettl Martin authored
75 ASSERT_EQUALS(true , MathLib::isLessEqual("1.00", "1.0"));
76 ASSERT_EQUALS(false , MathLib::isLessEqual("1.001", "1.0"));
77 ASSERT_EQUALS(false , MathLib::isLessEqual("1.0", "0.001"));
78 ASSERT_EQUALS(true , MathLib::isLessEqual("-1.0", "0.001"));
97f5380 added testing for mathlib
Daniel Marjamäki authored
79 }
80
6f8e42a @danmar changed the astyle formatting flags
authored
81 void calculate() {
24c5f4d astyle formatting
Daniel Marjamäki authored
82 // addition
e5c0383 @php-coder Strip redundant std::string usage from tests.
php-coder authored
83 ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
c2b3cfc extended testcases of mathlib; fixed zero conversion: +0 and -0 is co…
Martin Ettl authored
84 ASSERT_EQUALS("249", MathLib::add("250", "-1"));
85 ASSERT_EQUALS("251", MathLib::add("250", "1"));
86 ASSERT_EQUALS("-2" , MathLib::add("-1.", "-1"));
87 ASSERT_EQUALS("-1" , MathLib::add("0", "-1"));
88 ASSERT_EQUALS("1" , MathLib::add("1", "0"));
89 ASSERT_EQUALS("0" , MathLib::add("0", "0."));
90
24c5f4d astyle formatting
Daniel Marjamäki authored
91 // subtraction
c2b3cfc extended testcases of mathlib; fixed zero conversion: +0 and -0 is co…
Martin Ettl authored
92 ASSERT_EQUALS("254", MathLib::subtract("0xff", "1"));
93 ASSERT_EQUALS("251", MathLib::subtract("250", "-1"));
94 ASSERT_EQUALS("249", MathLib::subtract("250", "1"));
95 ASSERT_EQUALS("0" , MathLib::subtract("-1.", "-1"));
96 ASSERT_EQUALS("1" , MathLib::subtract("0", "-1"));
97 ASSERT_EQUALS("1" , MathLib::subtract("1", "0"));
98 ASSERT_EQUALS("0" , MathLib::subtract("0", "0."));
99
24c5f4d astyle formatting
Daniel Marjamäki authored
100 // multiply
88cc29e mathlib: added todo testcases for ticket #2200
Ettl Martin authored
101 ASSERT_EQUALS("-0.003" , MathLib::multiply("-1e-3", "3"));
102 ASSERT_EQUALS("-11.96" , MathLib::multiply("-2.3", "5.2"));
103 ASSERT_EQUALS("3000" , MathLib::multiply("1E3", "3"));
104 ASSERT_EQUALS("3000" , MathLib::multiply("1E+3", "3"));
105 ASSERT_EQUALS("3000" , MathLib::multiply("1.0E3", "3"));
106 ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E3", "3"));
107 ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E+3", "3"));
26f017e @danmar scripts: added tabs.pl - in my opinion it is bad to use tabs inside s…
authored
108 ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0"));
109 ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0"));
110 ASSERT_EQUALS("2147483648" , MathLib::multiply("2","1073741824"));
111 ASSERT_EQUALS("536870912" , MathLib::multiply("512","1048576"));
c2b3cfc extended testcases of mathlib; fixed zero conversion: +0 and -0 is co…
Martin Ettl authored
112
24c5f4d astyle formatting
Daniel Marjamäki authored
113 // divide
26f017e @danmar scripts: added tabs.pl - in my opinion it is bad to use tabs inside s…
authored
114 ASSERT_EQUALS("1" , MathLib::divide("1", "1"));
115 ASSERT_EQUALS("0" , MathLib::divide("0", "1"));
116 ASSERT_EQUALS("5" , MathLib::divide("-10", "-2"));
c2b3cfc extended testcases of mathlib; fixed zero conversion: +0 and -0 is co…
Martin Ettl authored
117 ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4"));
24c5f4d astyle formatting
Daniel Marjamäki authored
118 ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4"));
26f017e @danmar scripts: added tabs.pl - in my opinion it is bad to use tabs inside s…
authored
119 ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1"));
120 ASSERT_EQUALS("7" , MathLib::divide("21.", "3"));
121 ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
c2b3cfc extended testcases of mathlib; fixed zero conversion: +0 and -0 is co…
Martin Ettl authored
122
1943270 @aggro80 Add InternalError and change MathLib to throw it in case of an error.
aggro80 authored
123 // Unknown action should throw exception
124 ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError);
97f5380 added testing for mathlib
Daniel Marjamäki authored
125 }
7803466 testing mathlib: Test that conversion to numbers work
Daniel Marjamäki authored
126
7be01da @orbitcowboy fixed ticket 3693. Added modulus operator to Mathlib + unittests. Add…
orbitcowboy authored
127 void calculate1() { // mod
128 ASSERT_EQUALS("0" , MathLib::calculate("2" , "1" , '%'));
129 ASSERT_EQUALS("0" , MathLib::calculate("2.0" , "1.0" , '%'));
130 ASSERT_EQUALS("2" , MathLib::calculate("12" , "5" , '%'));
131 ASSERT_EQUALS("1" , MathLib::calculate("100" , "3" , '%'));
132 ASSERT_EQUALS("12" , MathLib::calculate("12.0" , "13.0" , '%'));
133 ASSERT_EQUALS("1.3" , MathLib::calculate("5.3" , "2.0" , '%'));
134 ASSERT_EQUALS("1.7" , MathLib::calculate("18.5" , "4.2" , '%'));
135 }
136
6f8e42a @danmar changed the astyle formatting flags
authored
137 void convert() {
24c5f4d astyle formatting
Daniel Marjamäki authored
138 // ------------------
139 // tolong conversion:
140 // ------------------
c3886a5 added further testcases to testmathlib::convert(); now the conversion…
Martin Ettl authored
141
24c5f4d astyle formatting
Daniel Marjamäki authored
142 // from hex
c3886a5 added further testcases to testmathlib::convert(); now the conversion…
Martin Ettl authored
143 ASSERT_EQUALS(10 , MathLib::toLongNumber("0xa"));
144 ASSERT_EQUALS(10995 , MathLib::toLongNumber("0x2AF3"));
145 ASSERT_EQUALS(-10 , MathLib::toLongNumber("-0xa"));
146 ASSERT_EQUALS(-10995, MathLib::toLongNumber("-0x2AF3"));
147 ASSERT_EQUALS(10 , MathLib::toLongNumber("+0xa"));
148 ASSERT_EQUALS(10995 , MathLib::toLongNumber("+0x2AF3"));
149
24c5f4d astyle formatting
Daniel Marjamäki authored
150 // from octal
c3886a5 added further testcases to testmathlib::convert(); now the conversion…
Martin Ettl authored
151 ASSERT_EQUALS(8 , MathLib::toLongNumber("010"));
152 ASSERT_EQUALS(8 , MathLib::toLongNumber("+010"));
153 ASSERT_EQUALS(-8 , MathLib::toLongNumber("-010"));
154 ASSERT_EQUALS(125 , MathLib::toLongNumber("0175"));
155 ASSERT_EQUALS(125 , MathLib::toLongNumber("+0175"));
156 ASSERT_EQUALS(-125 , MathLib::toLongNumber("-0175"));
157
24c5f4d astyle formatting
Daniel Marjamäki authored
158 // from base 10
c3886a5 added further testcases to testmathlib::convert(); now the conversion…
Martin Ettl authored
159 ASSERT_EQUALS(10 , MathLib::toLongNumber("10"));
160 ASSERT_EQUALS(10 , MathLib::toLongNumber("10."));
161 ASSERT_EQUALS(10 , MathLib::toLongNumber("10.0"));
162 ASSERT_EQUALS(100 , MathLib::toLongNumber("10E+1"));
163 ASSERT_EQUALS(1 , MathLib::toLongNumber("10E-1"));
164 ASSERT_EQUALS(100 , MathLib::toLongNumber("+10E+1"));
165 ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10E-1"));
166 ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.E+1"));
167 ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.E-1"));
168 ASSERT_EQUALS(100 , MathLib::toLongNumber("+10.0E+1"));
169 ASSERT_EQUALS(-1 , MathLib::toLongNumber("-10.0E-1"));
c391a03 added acos() check to ticket #1513; added testcases for MathLib::toDo…
Martin Ettl authored
170
a1d0def @aggro80 astyle fix
aggro80 authored
171 // -----------------
172 // to double number:
173 // -----------------
eb59bd5 @danmar Added -Wconversion compiler flag. The ASSERT_EQUALS_DOUBLE was added …
authored
174 ASSERT_EQUALS_DOUBLE(10.0 , MathLib::toDoubleNumber("10"));
175 ASSERT_EQUALS_DOUBLE(1000.0, MathLib::toDoubleNumber("10E+2"));
176 ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"));
177 ASSERT_EQUALS_DOUBLE(-100.0, MathLib::toDoubleNumber("-1.0E+2"));
178 ASSERT_EQUALS_DOUBLE(-1e+10, MathLib::toDoubleNumber("-1.0E+10"));
179 ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("+1.0E+2"));
180 ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("+1.0E+10"));
181 ASSERT_EQUALS_DOUBLE(100.0 , MathLib::toDoubleNumber("1.0E+2"));
182 ASSERT_EQUALS_DOUBLE(1e+10 , MathLib::toDoubleNumber("1.0E+10"));
183 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+0"));
184 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-0"));
185 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E+00"));
186 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0E-00"));
187 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0E+00"));
188 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0E-00"));
189 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0"));
190 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0."));
191 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("0.0"));
192 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0"));
193 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0"));
194 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0."));
195 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0."));
196 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("-0.0"));
197 ASSERT_EQUALS_DOUBLE(0.0 , MathLib::toDoubleNumber("+0.0"));
a1d0def @aggro80 astyle fix
aggro80 authored
198
7803466 testing mathlib: Test that conversion to numbers work
Daniel Marjamäki authored
199 }
8ab26e8 @aggro80 Don't warn about division by zero if zero if floating point number.
aggro80 authored
200
6f8e42a @danmar changed the astyle formatting flags
authored
201 void isint() {
24c5f4d astyle formatting
Daniel Marjamäki authored
202 // zero tests
f06adb1 added further testcases to testmathlib::isint()
Martin Ettl authored
203 ASSERT_EQUALS(true , MathLib::isInt("0"));
204 ASSERT_EQUALS(false, MathLib::isInt("0."));
205 ASSERT_EQUALS(false, MathLib::isInt("0.0"));
206 ASSERT_EQUALS(false, MathLib::isInt("-0."));
207 ASSERT_EQUALS(false, MathLib::isInt("+0."));
208 ASSERT_EQUALS(false, MathLib::isInt("-0.0"));
209 ASSERT_EQUALS(false, MathLib::isInt("+0.0"));
210 ASSERT_EQUALS(false, MathLib::isInt("+0.0E+1"));
211 ASSERT_EQUALS(false, MathLib::isInt("+0.0E-1"));
212 ASSERT_EQUALS(false, MathLib::isInt("-0.0E+1"));
213 ASSERT_EQUALS(false, MathLib::isInt("-0.0E-1"));
214
24c5f4d astyle formatting
Daniel Marjamäki authored
215 ASSERT_EQUALS(true , MathLib::isInt("1"));
216 ASSERT_EQUALS(true , MathLib::isInt("-1"));
f06adb1 added further testcases to testmathlib::isint()
Martin Ettl authored
217 ASSERT_EQUALS(true , MathLib::isInt("+1"));
218 ASSERT_EQUALS(true , MathLib::isInt("+1E+1"));
219 ASSERT_EQUALS(true , MathLib::isInt("+1E+10000"));
220 ASSERT_EQUALS(true , MathLib::isInt("-1E+1"));
221 ASSERT_EQUALS(true , MathLib::isInt("-1E+10000"));
222 ASSERT_EQUALS(false, MathLib::isInt("-1E-1"));
24c5f4d astyle formatting
Daniel Marjamäki authored
223 ASSERT_EQUALS(false, MathLib::isInt("-1E-10000"));
224
f06adb1 added further testcases to testmathlib::isint()
Martin Ettl authored
225 ASSERT_EQUALS(true, MathLib::isInt("0xff"));
8ab26e8 @aggro80 Don't warn about division by zero if zero if floating point number.
aggro80 authored
226 ASSERT_EQUALS(true, MathLib::isInt("0xa"));
227 ASSERT_EQUALS(true, MathLib::isInt("0l"));
228 ASSERT_EQUALS(true, MathLib::isInt("0L"));
229 ASSERT_EQUALS(true, MathLib::isInt("0ul"));
230 ASSERT_EQUALS(true, MathLib::isInt("0ull"));
231 ASSERT_EQUALS(true, MathLib::isInt("0llu"));
232 ASSERT_EQUALS(true, MathLib::isInt("333L"));
ed1c9be @aggro80 Fix ticket #632 (Mathlib isInt() identifies "330L" as not int)
aggro80 authored
233 ASSERT_EQUALS(true, MathLib::isInt("330L"));
234 ASSERT_EQUALS(true, MathLib::isInt("330llu"));
235 ASSERT_EQUALS(true, MathLib::isInt("07"));
236 ASSERT_EQUALS(true, MathLib::isInt("0123"));
8ab26e8 @aggro80 Don't warn about division by zero if zero if floating point number.
aggro80 authored
237 ASSERT_EQUALS(false, MathLib::isInt("0.4"));
238 ASSERT_EQUALS(false, MathLib::isInt("2352.3f"));
f06adb1 added further testcases to testmathlib::isint()
Martin Ettl authored
239 ASSERT_EQUALS(false, MathLib::isInt("0.00004"));
240 ASSERT_EQUALS(false, MathLib::isInt("2352.00001f"));
241 ASSERT_EQUALS(false, MathLib::isInt(".4"));
242 ASSERT_EQUALS(false, MathLib::isInt("1.0E+1"));
243 ASSERT_EQUALS(false, MathLib::isInt("1.0E-1"));
244 ASSERT_EQUALS(false, MathLib::isInt("-1.0E+1"));
245 ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1"));
246 ASSERT_EQUALS(false, MathLib::isInt("-1.E+1"));
247 ASSERT_EQUALS(false, MathLib::isInt("+1.E-1"));
0f284b4 coverage report fix: more testcases for mathlib::isInt() added in ord…
Martin Ettl authored
248 ASSERT_EQUALS(false, MathLib::isInt(" 1.0E+1"));
46a1118 @vBm Fixed some spelling mistakes
vBm authored
249 // with whitespace in front
0f284b4 coverage report fix: more testcases for mathlib::isInt() added in ord…
Martin Ettl authored
250 ASSERT_EQUALS(false, MathLib::isInt(" 1.0E-1"));
251 ASSERT_EQUALS(false, MathLib::isInt(" -1.0E+1"));
252 ASSERT_EQUALS(false, MathLib::isInt(" +1.0E-1"));
253 ASSERT_EQUALS(false, MathLib::isInt(" -1.E+1"));
254 ASSERT_EQUALS(false, MathLib::isInt(" +1.E-1"));
46a1118 @vBm Fixed some spelling mistakes
vBm authored
255 // with whitespace in front and end
0f284b4 coverage report fix: more testcases for mathlib::isInt() added in ord…
Martin Ettl authored
256 ASSERT_EQUALS(false, MathLib::isInt(" 1.0E-1 "));
257 ASSERT_EQUALS(false, MathLib::isInt(" -1.0E+1 "));
258 ASSERT_EQUALS(false, MathLib::isInt(" +1.0E-1 "));
259 ASSERT_EQUALS(false, MathLib::isInt(" -1.E+1 "));
260 ASSERT_EQUALS(false, MathLib::isInt(" +1.E-1 "));
46a1118 @vBm Fixed some spelling mistakes
vBm authored
261 // with whitespace in front and end
0f284b4 coverage report fix: more testcases for mathlib::isInt() added in ord…
Martin Ettl authored
262 ASSERT_EQUALS(false, MathLib::isInt("1.0E-1 "));
263 ASSERT_EQUALS(false, MathLib::isInt("-1.0E+1 "));
264 ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1 "));
265 ASSERT_EQUALS(false, MathLib::isInt("-1.E+1 "));
266 ASSERT_EQUALS(false, MathLib::isInt("+1.E-1 "));
1382832 mathlib:isInt() now handles calles of 'u' and 'l' correctly; testcase…
Martin Ettl authored
267 // test some garbage
268 ASSERT_EQUALS(false, MathLib::isInt("u"));
269 ASSERT_EQUALS(false, MathLib::isInt("l"));
270 ASSERT_EQUALS(false, MathLib::isInt("ul"));
271 ASSERT_EQUALS(false, MathLib::isInt("ll"));
272 ASSERT_EQUALS(false, MathLib::isInt("U"));
273 ASSERT_EQUALS(false, MathLib::isInt("L"));
274 ASSERT_EQUALS(false, MathLib::isInt("uL"));
275 ASSERT_EQUALS(false, MathLib::isInt("LL"));
8ab26e8 @aggro80 Don't warn about division by zero if zero if floating point number.
aggro80 authored
276 }
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
277
6f8e42a @danmar changed the astyle formatting flags
authored
278 void isnegative() {
8b5aae9 astyle formatting
Daniel Marjamäki authored
279 ASSERT_EQUALS(true, MathLib::isNegative("-1"));
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
280 ASSERT_EQUALS(true, MathLib::isNegative("-1."));
281 ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
282 ASSERT_EQUALS(true, MathLib::isNegative("-1.0E+2"));
283 ASSERT_EQUALS(true, MathLib::isNegative("-1.0E-2"));
284
8b5aae9 astyle formatting
Daniel Marjamäki authored
285 ASSERT_EQUALS(false, MathLib::isNegative("+1"));
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
286 ASSERT_EQUALS(false, MathLib::isNegative("+1."));
287 ASSERT_EQUALS(false, MathLib::isNegative("+1.0"));
288 ASSERT_EQUALS(false, MathLib::isNegative("+1.0E+2"));
8b5aae9 astyle formatting
Daniel Marjamäki authored
289 ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
290 }
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
291
6f8e42a @danmar changed the astyle formatting flags
authored
292 void isfloat() {
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
293 ASSERT_EQUALS(false, MathLib::isFloat("0"));
294 ASSERT_EQUALS(true , MathLib::isFloat("0."));
295 ASSERT_EQUALS(true , MathLib::isFloat("0.0"));
296 ASSERT_EQUALS(true , MathLib::isFloat("-0."));
297 ASSERT_EQUALS(true , MathLib::isFloat("+0."));
298 ASSERT_EQUALS(true , MathLib::isFloat("-0.0"));
299 ASSERT_EQUALS(true , MathLib::isFloat("+0.0"));
300 ASSERT_EQUALS(true , MathLib::isFloat("+0.0E+1"));
301 ASSERT_EQUALS(true , MathLib::isFloat("+0.0E-1"));
302 ASSERT_EQUALS(true , MathLib::isFloat("-0.0E+1"));
8b5aae9 astyle formatting
Daniel Marjamäki authored
303 ASSERT_EQUALS(true , MathLib::isFloat("-0.0E-1"));
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
304
305 ASSERT_EQUALS(false , MathLib::isFloat("1"));
306 ASSERT_EQUALS(false , MathLib::isFloat("-1"));
307 ASSERT_EQUALS(false , MathLib::isFloat("+1"));
308 ASSERT_EQUALS(false , MathLib::isFloat("+1E+1"));
309 ASSERT_EQUALS(false , MathLib::isFloat("+1E+10000"));
310 ASSERT_EQUALS(false , MathLib::isFloat("-1E+1"));
311 ASSERT_EQUALS(false , MathLib::isFloat("-1E+10000"));
9b66f7a #ticket 2429: added a test to the mathlib to ensure the used floating…
Ettl Martin authored
312 ASSERT_EQUALS(true , MathLib::isFloat(".1250E+04"));
b5fb01c ticket #1513 new check: Detecting obviously wrong math call arguments…
Martin Ettl authored
313 ASSERT_EQUALS(true , MathLib::isFloat("-1E-1"));
314 ASSERT_EQUALS(true , MathLib::isFloat("-1E-10000"));
315
316 ASSERT_EQUALS(true , MathLib::isFloat("0.4"));
317 ASSERT_EQUALS(true , MathLib::isFloat("2352.3f"));
318 ASSERT_EQUALS(true , MathLib::isFloat("0.00004"));
319 ASSERT_EQUALS(true , MathLib::isFloat("2352.00001f"));
320 ASSERT_EQUALS(true , MathLib::isFloat(".4"));
321 ASSERT_EQUALS(true , MathLib::isFloat("1.0E+1"));
322 ASSERT_EQUALS(true , MathLib::isFloat("1.0E-1"));
323 ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1"));
8b5aae9 astyle formatting
Daniel Marjamäki authored
324 }
97f5380 added testing for mathlib
Daniel Marjamäki authored
325 };
326
327 REGISTER_TEST(TestMathLib)
328
329
Something went wrong with that request. Please try again.