2009-04-06 19:08:13 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2021-03-21 20:58:32 +01:00
|
|
|
* Copyright (C) 2007-2021 Cppcheck team.
|
2009-04-06 19:08:13 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-06 19:08:13 +02:00
|
|
|
*/
|
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2009-10-25 12:49:06 +01:00
|
|
|
#include "mathlib.h"
|
2009-04-06 19:08:13 +02:00
|
|
|
#include "testsuite.h"
|
|
|
|
|
2021-02-13 19:10:45 +01:00
|
|
|
#include <limits>
|
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
struct InternalError;
|
|
|
|
|
2015-03-11 22:26:33 +01:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
class TestMathLib : public TestFixture {
|
2009-04-06 19:08:13 +02:00
|
|
|
public:
|
2021-08-07 20:51:18 +02:00
|
|
|
TestMathLib() : TestFixture("TestMathLib") {}
|
2009-04-06 19:08:13 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2019-01-12 15:45:25 +01:00
|
|
|
void run() OVERRIDE {
|
2009-09-01 21:06:46 +02:00
|
|
|
TEST_CASE(isint);
|
2014-03-10 17:23:07 +01:00
|
|
|
TEST_CASE(isbin);
|
2014-11-14 21:43:37 +01:00
|
|
|
TEST_CASE(isdec);
|
2014-03-09 21:14:14 +01:00
|
|
|
TEST_CASE(isoct);
|
2015-07-26 19:21:53 +02:00
|
|
|
TEST_CASE(isFloatHex);
|
|
|
|
TEST_CASE(isIntHex);
|
2015-07-26 08:06:56 +02:00
|
|
|
TEST_CASE(isValidIntegerSuffix);
|
2010-04-02 02:19:38 +02:00
|
|
|
TEST_CASE(isnegative);
|
2013-09-29 15:11:09 +02:00
|
|
|
TEST_CASE(ispositive);
|
2015-07-26 19:47:27 +02:00
|
|
|
TEST_CASE(isFloat);
|
2015-07-26 19:21:53 +02:00
|
|
|
TEST_CASE(isDecimalFloat);
|
2020-04-21 17:27:51 +02:00
|
|
|
TEST_CASE(isGreater);
|
|
|
|
TEST_CASE(isGreaterEqual);
|
|
|
|
TEST_CASE(isEqual);
|
|
|
|
TEST_CASE(isNotEqual);
|
|
|
|
TEST_CASE(isLess);
|
|
|
|
TEST_CASE(isLessEqual);
|
2014-04-10 22:46:55 +02:00
|
|
|
TEST_CASE(calculate);
|
|
|
|
TEST_CASE(calculate1);
|
2015-06-15 19:01:56 +02:00
|
|
|
TEST_CASE(typesuffix);
|
2015-11-20 18:57:48 +01:00
|
|
|
TEST_CASE(toLongNumber);
|
|
|
|
TEST_CASE(toDoubleNumber);
|
2014-04-11 01:27:05 +02:00
|
|
|
TEST_CASE(naninf);
|
|
|
|
TEST_CASE(isNullValue);
|
2014-05-29 18:25:01 +02:00
|
|
|
TEST_CASE(incdec);
|
2014-11-16 18:09:21 +01:00
|
|
|
TEST_CASE(sin);
|
|
|
|
TEST_CASE(cos);
|
|
|
|
TEST_CASE(tan);
|
|
|
|
TEST_CASE(abs);
|
2014-12-03 18:24:27 +01:00
|
|
|
TEST_CASE(toString);
|
2016-06-04 22:55:55 +02:00
|
|
|
TEST_CASE(CPP14DigitSeparators);
|
2011-07-19 09:10:34 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isGreater() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isGreater("1.0", "0.001"));
|
2011-07-19 09:10:34 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isGreater("-1.0", "0.001"));
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isGreaterEqual() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isGreaterEqual("1.00", "1.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isGreaterEqual("1.001", "1.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isGreaterEqual("1.0", "0.001"));
|
2011-07-19 09:10:34 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isGreaterEqual("-1.0", "0.001"));
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isEqual() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isEqual("1.0", "1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isEqual("1.", "1.01"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isEqual("0.1","1.0E-1"));
|
2011-07-19 09:10:34 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isNotEqual() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNotEqual("1.0", "1.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNotEqual("1.", "1.01"));
|
2011-07-19 09:10:34 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isLess() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isLess("1.0", "0.001"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isLess("-1.0", "0.001"));
|
2011-07-19 09:10:34 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isLessEqual() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isLessEqual("1.00", "1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isLessEqual("1.001", "1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isLessEqual("1.0", "0.001"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isLessEqual("-1.0", "0.001"));
|
2009-04-06 19:08:13 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void calculate() const {
|
2009-12-27 17:46:24 +01:00
|
|
|
// addition
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
|
|
|
|
ASSERT_EQUALS("249", MathLib::add("250", "-1"));
|
|
|
|
ASSERT_EQUALS("251", MathLib::add("250", "1"));
|
|
|
|
ASSERT_EQUALS("-2.0", MathLib::add("-1.", "-1"));
|
|
|
|
ASSERT_EQUALS("-1", MathLib::add("0", "-1"));
|
|
|
|
ASSERT_EQUALS("1", MathLib::add("1", "0"));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::add("0", "0."));
|
|
|
|
ASSERT_EQUALS("1.00000001", MathLib::add("1", "0.00000001")); // #4016
|
|
|
|
ASSERT_EQUALS("30666.22", MathLib::add("30666.22", "0.0")); // #4068
|
2009-12-27 14:30:23 +01:00
|
|
|
|
2009-12-27 17:46:24 +01:00
|
|
|
// subtraction
|
2009-12-27 14:30:23 +01:00
|
|
|
ASSERT_EQUALS("254", MathLib::subtract("0xff", "1"));
|
|
|
|
ASSERT_EQUALS("251", MathLib::subtract("250", "-1"));
|
|
|
|
ASSERT_EQUALS("249", MathLib::subtract("250", "1"));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0.0", MathLib::subtract("-1.", "-1"));
|
|
|
|
ASSERT_EQUALS("1", MathLib::subtract("0", "-1"));
|
|
|
|
ASSERT_EQUALS("1", MathLib::subtract("1", "0"));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::subtract("0", "0."));
|
|
|
|
ASSERT_EQUALS("0.99999999", MathLib::subtract("1", "0.00000001")); // #4016
|
|
|
|
ASSERT_EQUALS("30666.22", MathLib::subtract("30666.22", "0.0")); // #4068
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::subtract("0.0", "0.0"));
|
2009-12-27 14:30:23 +01:00
|
|
|
|
2009-12-27 17:46:24 +01:00
|
|
|
// multiply
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("-0.003", MathLib::multiply("-1e-3", "3"));
|
|
|
|
ASSERT_EQUALS("-11.96", MathLib::multiply("-2.3", "5.2"));
|
|
|
|
ASSERT_EQUALS("3000.0", MathLib::multiply("1E3", "3"));
|
|
|
|
ASSERT_EQUALS("3000.0", MathLib::multiply("1E+3", "3"));
|
|
|
|
ASSERT_EQUALS("3000.0", MathLib::multiply("1.0E3", "3"));
|
|
|
|
ASSERT_EQUALS("-3000.0", MathLib::multiply("-1.0E3", "3"));
|
|
|
|
ASSERT_EQUALS("-3000.0", MathLib::multiply("-1.0E+3", "3"));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::multiply("+1.0E+3", "0"));
|
|
|
|
ASSERT_EQUALS("2147483648", MathLib::multiply("2","1073741824"));
|
|
|
|
ASSERT_EQUALS("536870912", MathLib::multiply("512","1048576"));
|
2009-12-27 14:30:23 +01:00
|
|
|
|
2009-12-27 17:46:24 +01:00
|
|
|
// divide
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("1", MathLib::divide("1", "1"));
|
|
|
|
ASSERT_EQUALS("0", MathLib::divide("0", "1"));
|
|
|
|
ASSERT_EQUALS("5", MathLib::divide("-10", "-2"));
|
2009-12-27 14:30:23 +01:00
|
|
|
ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4"));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("2.5", MathLib::divide("-10.", "-4"));
|
|
|
|
ASSERT_EQUALS("5.0", MathLib::divide("25.5", "5.1"));
|
|
|
|
ASSERT_EQUALS("7.0", MathLib::divide("21.", "3"));
|
|
|
|
ASSERT_EQUALS("1", MathLib::divide("3", "2"));
|
2019-05-25 23:06:50 +02:00
|
|
|
ASSERT_THROW(MathLib::divide("123", "0"), InternalError); // decimal zero: throw
|
|
|
|
ASSERT_THROW(MathLib::divide("123", "00"), InternalError); // octal zero: throw
|
|
|
|
ASSERT_THROW(MathLib::divide("123", "0x0"), InternalError); // hex zero: throw
|
|
|
|
MathLib::divide("123", "0.0f"); // float zero: don't throw
|
|
|
|
MathLib::divide("123", "0.0"); // double zero: don't throw
|
|
|
|
MathLib::divide("123", "0.0L"); // long double zero: don't throw
|
2013-05-09 18:50:24 +02:00
|
|
|
ASSERT_THROW(MathLib::divide("-9223372036854775808", "-1"), InternalError); // #4520 - out of range => throw
|
2015-06-20 23:15:35 +02:00
|
|
|
ASSERT_EQUALS("4611686018427387904", MathLib::divide("-9223372036854775808", "-2")); // #6679
|
2019-05-25 23:06:50 +02:00
|
|
|
|
2009-12-27 14:30:23 +01:00
|
|
|
|
2020-01-09 16:18:03 +01:00
|
|
|
// invoke for each supported action
|
|
|
|
ASSERT_EQUALS("3", MathLib::calculate("2", "1", '+'));
|
|
|
|
ASSERT_EQUALS("1", MathLib::calculate("2", "1", '-'));
|
|
|
|
ASSERT_EQUALS("2", MathLib::calculate("2", "1", '*'));
|
|
|
|
ASSERT_EQUALS("2", MathLib::calculate("2", "1", '/'));
|
|
|
|
ASSERT_EQUALS("0", MathLib::calculate("2", "1", '%'));
|
|
|
|
ASSERT_EQUALS("0", MathLib::calculate("1", "2", '&'));
|
|
|
|
ASSERT_EQUALS("1", MathLib::calculate("1", "1", '|'));
|
|
|
|
ASSERT_EQUALS("1", MathLib::calculate("0", "1", '^'));
|
|
|
|
|
2012-01-08 21:19:44 +01:00
|
|
|
// Unknown action should throw exception
|
|
|
|
ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError);
|
2009-04-06 19:08:13 +02:00
|
|
|
}
|
2009-05-02 11:12:49 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void calculate1() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0", MathLib::calculate("2", "1", '%'));
|
|
|
|
ASSERT_EQUALS("2", MathLib::calculate("12", "5", '%'));
|
|
|
|
ASSERT_EQUALS("1", MathLib::calculate("100", "3", '%'));
|
2015-07-15 17:36:41 +02:00
|
|
|
|
|
|
|
#ifndef TEST_MATHLIB_VALUE
|
|
|
|
// floating point modulo is not defined in C/C++
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0.0", MathLib::calculate("2.0", "1.0", '%'));
|
|
|
|
ASSERT_EQUALS("12.0", MathLib::calculate("12.0", "13.0", '%'));
|
|
|
|
ASSERT_EQUALS("1.3", MathLib::calculate("5.3", "2.0", '%'));
|
|
|
|
ASSERT_EQUALS("1.7", MathLib::calculate("18.5", "4.2", '%'));
|
2012-09-06 20:15:32 +02:00
|
|
|
MathLib::calculate("123", "0.0", '%'); // don't throw
|
2015-07-15 17:36:41 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ASSERT_THROW(MathLib::calculate("123", "0", '%'), InternalError); // throw
|
2014-11-16 18:09:21 +01:00
|
|
|
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0", MathLib::calculate("1", "1", '^'));
|
|
|
|
ASSERT_EQUALS("3", MathLib::calculate("2", "1", '^'));
|
2012-04-12 14:02:09 +02:00
|
|
|
}
|
|
|
|
|
2015-06-15 19:01:56 +02:00
|
|
|
void typesuffix() const {
|
|
|
|
ASSERT_EQUALS("2", MathLib::add("1", "1"));
|
|
|
|
ASSERT_EQUALS("2U", MathLib::add("1U", "1"));
|
|
|
|
ASSERT_EQUALS("2L", MathLib::add("1L", "1"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1UL", "1"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1"));
|
2016-07-26 13:19:28 +02:00
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1i64", "1"));
|
2015-06-15 19:01:56 +02:00
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1"));
|
2016-07-26 13:19:28 +02:00
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ui64","1"));
|
2015-06-15 19:01:56 +02:00
|
|
|
|
|
|
|
ASSERT_EQUALS("2U", MathLib::add("1", "1U"));
|
|
|
|
ASSERT_EQUALS("2U", MathLib::add("1U", "1U"));
|
|
|
|
ASSERT_EQUALS("2L", MathLib::add("1L", "1U"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1UL", "1U"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1U"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1U"));
|
|
|
|
|
|
|
|
ASSERT_EQUALS("2L", MathLib::add("1", "1L"));
|
|
|
|
ASSERT_EQUALS("2L", MathLib::add("1U", "1L"));
|
|
|
|
ASSERT_EQUALS("2L", MathLib::add("1L", "1L"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1UL", "1L"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1L"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1L"));
|
|
|
|
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1", "1UL"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1U", "1UL"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1L", "1UL"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1UL", "1UL"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1UL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1UL"));
|
|
|
|
|
2015-06-16 19:12:18 +02:00
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1", "1LU"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1U", "1LU"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1L", "1LU"));
|
|
|
|
ASSERT_EQUALS("2UL", MathLib::add("1UL", "1LU"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1LU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1LU"));
|
|
|
|
|
2015-06-15 19:01:56 +02:00
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1", "1LL"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1U", "1LL"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1L", "1LL"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1UL", "1LL"));
|
|
|
|
ASSERT_EQUALS("2LL", MathLib::add("1LL", "1LL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1LL"));
|
|
|
|
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1", "1ULL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1U", "1ULL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1L", "1ULL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1UL", "1ULL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1LL", "1ULL"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1ULL"));
|
2015-06-16 19:12:18 +02:00
|
|
|
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1", "1LLU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1U", "1LLU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1L", "1LLU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1UL", "1LLU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1LL", "1LLU"));
|
|
|
|
ASSERT_EQUALS("2ULL", MathLib::add("1ULL", "1LLU"));
|
2015-06-15 19:01:56 +02:00
|
|
|
}
|
|
|
|
|
2015-11-20 18:57:48 +01:00
|
|
|
void toLongNumber() const {
|
2009-12-27 17:46:24 +01:00
|
|
|
// from hex
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(0, MathLib::toLongNumber("0x0"));
|
|
|
|
ASSERT_EQUALS(0, MathLib::toLongNumber("-0x0"));
|
|
|
|
ASSERT_EQUALS(0, MathLib::toLongNumber("+0x0"));
|
|
|
|
ASSERT_EQUALS(10, MathLib::toLongNumber("0xa"));
|
|
|
|
ASSERT_EQUALS(10995, MathLib::toLongNumber("0x2AF3"));
|
|
|
|
ASSERT_EQUALS(-10, MathLib::toLongNumber("-0xa"));
|
2009-12-27 15:18:18 +01:00
|
|
|
ASSERT_EQUALS(-10995, MathLib::toLongNumber("-0x2AF3"));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(10, MathLib::toLongNumber("+0xa"));
|
|
|
|
ASSERT_EQUALS(10995, MathLib::toLongNumber("+0x2AF3"));
|
2009-12-27 15:18:18 +01:00
|
|
|
|
2009-12-27 17:46:24 +01:00
|
|
|
// from octal
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(8, MathLib::toLongNumber("010"));
|
|
|
|
ASSERT_EQUALS(8, MathLib::toLongNumber("+010"));
|
|
|
|
ASSERT_EQUALS(-8, MathLib::toLongNumber("-010"));
|
|
|
|
ASSERT_EQUALS(125, MathLib::toLongNumber("0175"));
|
|
|
|
ASSERT_EQUALS(125, MathLib::toLongNumber("+0175"));
|
|
|
|
ASSERT_EQUALS(-125, MathLib::toLongNumber("-0175"));
|
2009-12-27 15:18:18 +01:00
|
|
|
|
2012-09-10 21:13:32 +02:00
|
|
|
// from binary
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(0, MathLib::toLongNumber("0b0"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1"));
|
2020-01-12 08:11:12 +01:00
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1U"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1L"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1LU"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1LL"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("0b1LLU"));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("+0b1"));
|
|
|
|
ASSERT_EQUALS(-1, MathLib::toLongNumber("-0b1"));
|
|
|
|
ASSERT_EQUALS(215, MathLib::toLongNumber("0b11010111"));
|
|
|
|
ASSERT_EQUALS(-215, MathLib::toLongNumber("-0b11010111"));
|
|
|
|
ASSERT_EQUALS(215, MathLib::toLongNumber("0B11010111"));
|
2012-09-10 21:13:32 +02:00
|
|
|
|
2009-12-27 17:46:24 +01:00
|
|
|
// from base 10
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(10, MathLib::toLongNumber("10"));
|
|
|
|
ASSERT_EQUALS(10, MathLib::toLongNumber("10."));
|
|
|
|
ASSERT_EQUALS(10, MathLib::toLongNumber("10.0"));
|
|
|
|
ASSERT_EQUALS(100, MathLib::toLongNumber("10E+1"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toLongNumber("10E-1"));
|
|
|
|
ASSERT_EQUALS(100, MathLib::toLongNumber("+10E+1"));
|
|
|
|
ASSERT_EQUALS(-1, MathLib::toLongNumber("-10E-1"));
|
|
|
|
ASSERT_EQUALS(100, MathLib::toLongNumber("+10.E+1"));
|
|
|
|
ASSERT_EQUALS(-1, MathLib::toLongNumber("-10.E-1"));
|
|
|
|
ASSERT_EQUALS(100, MathLib::toLongNumber("+10.0E+1"));
|
|
|
|
ASSERT_EQUALS(-1, MathLib::toLongNumber("-10.0E-1"));
|
2015-06-28 12:34:08 +02:00
|
|
|
|
2015-11-20 18:57:48 +01:00
|
|
|
// from char
|
|
|
|
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'"));
|
2016-10-16 13:42:20 +02:00
|
|
|
ASSERT_EQUALS((int)('\x10'), MathLib::toLongNumber("'\\x10'"));
|
|
|
|
ASSERT_EQUALS((int)('\100'), MathLib::toLongNumber("'\\100'"));
|
|
|
|
ASSERT_EQUALS((int)('\200'), MathLib::toLongNumber("'\\200'"));
|
2019-10-16 11:41:33 +02:00
|
|
|
ASSERT_EQUALS((int)(L'A'), MathLib::toLongNumber("L'A'"));
|
2015-11-23 20:41:21 +01:00
|
|
|
|
2015-06-28 12:34:08 +02:00
|
|
|
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));
|
|
|
|
ASSERT_EQUALS(-8481036456200365558, MathLib::toLongNumber("0x8a4d4e470d0a1a0a"));
|
|
|
|
ASSERT_EQUALS(9894494448401390090ULL, MathLib::toULongNumber("0x89504e470d0a1a0a"));
|
|
|
|
ASSERT_EQUALS(9965707617509186058ULL, MathLib::toULongNumber("0x8a4d4e470d0a1a0a"));
|
2010-04-02 20:23:37 +02:00
|
|
|
|
2014-12-03 18:24:27 +01:00
|
|
|
// zero input
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(0, MathLib::toULongNumber("0"));
|
|
|
|
ASSERT_EQUALS(0, MathLib::toULongNumber("-0"));
|
|
|
|
ASSERT_EQUALS(0, MathLib::toULongNumber("+0"));
|
|
|
|
ASSERT_EQUALS(0U, MathLib::toULongNumber("0U"));
|
|
|
|
ASSERT_EQUALS(0, MathLib::toULongNumber("-0x0"));
|
|
|
|
|
|
|
|
ASSERT_EQUALS(1U, MathLib::toULongNumber("1U"));
|
|
|
|
ASSERT_EQUALS(10000U, MathLib::toULongNumber("1e4"));
|
|
|
|
ASSERT_EQUALS(10000U, MathLib::toULongNumber("1e4"));
|
2014-11-26 17:35:32 +01:00
|
|
|
ASSERT_EQUALS(0xFF00000000000000UL, MathLib::toULongNumber("0xFF00000000000000UL"));
|
|
|
|
ASSERT_EQUALS(0x0A00000000000000UL, MathLib::toULongNumber("0x0A00000000000000UL"));
|
2020-01-12 08:11:12 +01:00
|
|
|
ASSERT_EQUALS(0, MathLib::toULongNumber("0b0"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1U"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1L"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1LU"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1LL"));
|
|
|
|
ASSERT_EQUALS(1, MathLib::toULongNumber("0b1LLU"));
|
2014-11-26 17:35:32 +01:00
|
|
|
ASSERT_EQUALS(9U, MathLib::toULongNumber("011"));
|
|
|
|
ASSERT_EQUALS(5U, MathLib::toULongNumber("0b101"));
|
|
|
|
|
2012-11-27 17:37:49 +01:00
|
|
|
// from long long
|
2015-06-28 12:34:08 +02:00
|
|
|
/*
|
2015-11-22 16:56:44 +01:00
|
|
|
* ASSERT_EQUALS(0xFF00000000000000LL, MathLib::toLongNumber("0xFF00000000000000LL"));
|
2015-06-28 12:34:08 +02:00
|
|
|
* This does not work in a portable way!
|
2015-07-15 15:29:35 +02:00
|
|
|
* While it succeeds on 32bit Visual Studio it fails on Linux 64bit because it is greater than 0x7FFFFFFFFFFFFFFF (=LLONG_MAX)
|
2015-11-22 16:56:44 +01:00
|
|
|
*/
|
2015-06-28 12:34:08 +02:00
|
|
|
|
2012-11-27 17:37:49 +01:00
|
|
|
ASSERT_EQUALS(0x0A00000000000000LL, MathLib::toLongNumber("0x0A00000000000000LL"));
|
2021-02-13 19:10:45 +01:00
|
|
|
|
|
|
|
// min/max numeric limits
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<long long>::min(), MathLib::toLongNumber(std::to_string(std::numeric_limits<long long>::min())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<long long>::max(), MathLib::toLongNumber(std::to_string(std::numeric_limits<long long>::max())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<unsigned long long>::min(), MathLib::toLongNumber(std::to_string(std::numeric_limits<unsigned long long>::min())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<unsigned long long>::max(), MathLib::toLongNumber(std::to_string(std::numeric_limits<unsigned long long>::max())));
|
|
|
|
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<long long>::min(), MathLib::toULongNumber(std::to_string(std::numeric_limits<long long>::min())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<long long>::max(), MathLib::toULongNumber(std::to_string(std::numeric_limits<long long>::max())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<unsigned long long>::min(), MathLib::toULongNumber(std::to_string(std::numeric_limits<unsigned long long>::min())));
|
|
|
|
ASSERT_EQUALS(std::numeric_limits<unsigned long long>::max(), MathLib::toULongNumber(std::to_string(std::numeric_limits<unsigned long long>::max())));
|
|
|
|
|
|
|
|
// min/max and out-of-bounds - hex
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = 0xFFFFFFFFFFFFFFFF;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("0xFFFFFFFFFFFFFFFF"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = 0xFFFFFFFFFFFFFFFF;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("0xFFFFFFFFFFFFFFFF"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = -0xFFFFFFFFFFFFFFFF;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("-0xFFFFFFFFFFFFFFFF"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = -0xFFFFFFFFFFFFFFFF;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("-0xFFFFFFFFFFFFFFFF"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("0x10000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("0x10000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("-0x10000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("-0x10000000000000000"), InternalError);
|
|
|
|
|
|
|
|
// min/max and out-of-bounds - octal
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = 01777777777777777777777;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("01777777777777777777777"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = 01777777777777777777777;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("01777777777777777777777"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = -01777777777777777777777;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("-01777777777777777777777"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = -01777777777777777777777;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("-01777777777777777777777"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("02000000000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("02000000000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("-02000000000000000000000"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("-02000000000000000000000"), InternalError);
|
|
|
|
|
|
|
|
// min/max and out-of-bounds - decimal
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = 18446744073709551615;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("18446744073709551615"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = 18446744073709551615;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("18446744073709551615"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::bigint i = -18446744073709551615;
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber(std::to_string(i)));
|
|
|
|
ASSERT_EQUALS(i, MathLib::toLongNumber("-18446744073709551615"));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const MathLib::biguint u = -18446744073709551615;
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber(std::to_string(u)));
|
|
|
|
ASSERT_EQUALS(u, MathLib::toULongNumber("-18446744073709551615"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("18446744073709551616"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("18446744073709551616"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toLongNumber("-18446744073709551616"), InternalError);
|
|
|
|
ASSERT_THROW(MathLib::toULongNumber("-18446744073709551616"), InternalError);
|
|
|
|
|
|
|
|
// TODO: test binary
|
|
|
|
// TODO: test floating point
|
|
|
|
|
|
|
|
// TODO: test with 128-bit values
|
2015-11-20 18:57:48 +01:00
|
|
|
}
|
2012-11-27 17:37:49 +01:00
|
|
|
|
2017-01-07 14:13:22 +01:00
|
|
|
void toDoubleNumber() const {
|
2020-01-21 17:29:33 +01:00
|
|
|
ASSERT_EQUALS_DOUBLE(1.0, MathLib::toDoubleNumber("1"), 0.001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(1.0, MathLib::toDoubleNumber("0x1"), 0.001);
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS_DOUBLE(10.0, MathLib::toDoubleNumber("10"), 0.001);
|
2017-10-10 22:40:49 +02:00
|
|
|
ASSERT_EQUALS_DOUBLE(1000.0, MathLib::toDoubleNumber("10E+2"), 0.001);
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS_DOUBLE(100.0, MathLib::toDoubleNumber("1.0E+2"), 0.001);
|
2017-10-10 22:40:49 +02:00
|
|
|
ASSERT_EQUALS_DOUBLE(-100.0, MathLib::toDoubleNumber("-1.0E+2"), 0.001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(-1e+10, MathLib::toDoubleNumber("-1.0E+10"), 1);
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS_DOUBLE(100.0, MathLib::toDoubleNumber("+1.0E+2"), 0.001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(1e+10, MathLib::toDoubleNumber("+1.0E+10"), 1);
|
|
|
|
ASSERT_EQUALS_DOUBLE(100.0, MathLib::toDoubleNumber("1.0E+2"), 0.001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(1e+10, MathLib::toDoubleNumber("1.0E+10"), 1);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0E+0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0E-0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0E+00"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0E-00"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0E+00"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0E-00"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0."), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("0.0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0."), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0."), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("-0.0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0, MathLib::toDoubleNumber("+0.0"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE('0', MathLib::toDoubleNumber("'0'"), 0.000001);
|
2019-10-16 11:41:33 +02:00
|
|
|
ASSERT_EQUALS_DOUBLE(L'0', MathLib::toDoubleNumber("L'0'"), 0.000001);
|
2010-04-02 20:42:06 +02:00
|
|
|
|
2018-12-06 22:16:16 +01:00
|
|
|
ASSERT_EQUALS_DOUBLE(192, MathLib::toDoubleNumber("0x0.3p10"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(5.42101e-20, MathLib::toDoubleNumber("0x1p-64"), 1e-20);
|
|
|
|
ASSERT_EQUALS_DOUBLE(3.14159, MathLib::toDoubleNumber("0x1.921fb5p+1"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(2006, MathLib::toDoubleNumber("0x1.f58000p+10"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(1e-010, MathLib::toDoubleNumber("0x1.b7cdfep-34"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(.484375, MathLib::toDoubleNumber("0x1.fp-2"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(9.0, MathLib::toDoubleNumber("0x1.2P3"), 0.000001);
|
|
|
|
ASSERT_EQUALS_DOUBLE(0.0625, MathLib::toDoubleNumber("0x.1P0"), 0.000001);
|
|
|
|
|
2013-09-29 18:11:17 +02:00
|
|
|
// verify: string --> double --> string conversion
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0f")));
|
|
|
|
ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("1.0")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("0.0f")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("0.0")));
|
|
|
|
ASSERT_EQUALS("-1.0", MathLib::toString(MathLib::toDoubleNumber("-1.0f")));
|
|
|
|
ASSERT_EQUALS("-1.0", MathLib::toString(MathLib::toDoubleNumber("-1.0")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("-0.0f")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("-0.0")));
|
|
|
|
ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("+1.0f")));
|
|
|
|
ASSERT_EQUALS("1.0", MathLib::toString(MathLib::toDoubleNumber("+1.0")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("+0.0f")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("+0.0")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("-0")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("-0.")));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(MathLib::toDoubleNumber("-0.0")));
|
2009-05-02 11:12:49 +02:00
|
|
|
}
|
2009-09-01 21:06:46 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isint() const {
|
2009-12-27 17:46:24 +01:00
|
|
|
// zero tests
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0"));
|
2009-12-27 14:46:47 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-0."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+0."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-0.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+0.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+0.0E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+0.0E-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-0.0E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-0.0E-1"));
|
|
|
|
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1E+10000"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1E+10000"));
|
2009-12-27 14:46:47 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1E-1"));
|
2009-12-27 17:46:24 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1E-10000"));
|
|
|
|
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0xff"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0xa"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0b1000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0B1000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0ul"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0ull"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0llu"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("333L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("330L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("330llu"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("07"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isInt("0123"));
|
2009-09-01 21:06:46 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0.4"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("2352.3f"));
|
2009-12-27 14:46:47 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0.00004"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("2352.00001f"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(".4"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("1.0E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("1.0E-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1.0E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1.E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1.E-1"));
|
2010-04-02 22:18:50 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" 1.0E+1"));
|
2010-12-15 18:45:53 +01:00
|
|
|
// with whitespace in front
|
2010-04-02 22:18:50 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" 1.0E-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" -1.0E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" +1.0E-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" -1.E+1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" +1.E-1"));
|
2010-12-15 18:45:53 +01:00
|
|
|
// with whitespace in front and end
|
2010-04-02 22:18:50 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" 1.0E-1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" -1.0E+1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" +1.0E-1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" -1.E+1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(" +1.E-1 "));
|
2010-12-15 18:45:53 +01:00
|
|
|
// with whitespace in front and end
|
2010-04-02 22:18:50 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("1.0E-1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1.0E+1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("-1.E+1 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("+1.E-1 "));
|
2010-05-12 23:49:09 +02:00
|
|
|
// test some garbage
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("u"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("l"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("ul"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("ll"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("U"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("L"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("uL"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("LL"));
|
2014-02-20 16:56:49 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("e2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("E2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(".e2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(".E2"));
|
2014-03-16 11:55:44 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0xu"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0xl"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt("0xul"));
|
|
|
|
// test empty string
|
|
|
|
ASSERT_EQUALS(false, MathLib::isInt(""));
|
2009-09-01 21:06:46 +02:00
|
|
|
}
|
2010-04-02 02:19:38 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isbin() const {
|
2014-03-10 17:23:07 +01:00
|
|
|
// positive testing
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("+0b1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("-0b1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("-0b11010111"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0B11010111"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111u"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111ul"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111ull"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111ll"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111llu"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isBin("0b11010111lu"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111lul")); // Suffix LUL not allowed
|
|
|
|
|
|
|
|
// negative testing
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("100101bx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0B"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0C"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("+0B"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("-0B"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("-0Bx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111ux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111lx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111lux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111ulx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111lulx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111ullx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin("0b11010111lll"));
|
|
|
|
|
|
|
|
// test empty string
|
|
|
|
ASSERT_EQUALS(false, MathLib::isBin(""));
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isnegative() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNegative("-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNegative("-1."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E+2"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNegative("-1.0E-2"));
|
2010-04-02 02:19:38 +02:00
|
|
|
|
2010-04-02 07:32:03 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative("+1"));
|
2010-04-02 02:19:38 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative("+1."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E+2"));
|
2010-04-02 07:32:03 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative("+1.0E-2"));
|
2014-03-16 11:55:44 +01:00
|
|
|
// test empty string
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNegative(""));
|
2010-04-02 07:32:03 +02:00
|
|
|
}
|
2010-04-02 02:19:38 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isoct() const {
|
2014-03-09 21:14:14 +01:00
|
|
|
// octal number format: [+|-]0[0-7][suffix]
|
|
|
|
// positive testing
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("010"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+010"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-010"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("0175"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+0175"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-0175"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("00"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("02"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("+042LLU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isOct("-042LLU"));
|
|
|
|
|
|
|
|
// test empty string
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct(""));
|
|
|
|
|
|
|
|
// negative testing
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-0x175"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-0_garbage_"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct(" "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct(" "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("02."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("02E2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042Ux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042Ux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042Lx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042Lx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042ULx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042ULx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042LLx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042LLx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042ULLx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042ULLx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042LLUx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042LLUx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042LUL"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042LUL"));
|
|
|
|
// white space in front
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct(" -042ULL"));
|
|
|
|
// trailing white space
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("-042ULL "));
|
|
|
|
// front and trailing white space
|
|
|
|
ASSERT_EQUALS(false, MathLib::isOct(" -042ULL "));
|
2014-04-10 22:46:55 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isOct("+042LUL+0"));
|
2014-03-09 21:14:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-26 19:21:53 +02:00
|
|
|
void isFloatHex() const {
|
2015-07-26 08:06:56 +02:00
|
|
|
// hex number syntax: [sign]0x[hexnumbers][suffix]
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.999999999999ap-4"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x0.3p10"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.fp3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1P-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0xcc.ccccccccccdp-11"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x3.243F6A88p+03"));
|
2015-07-26 19:47:27 +02:00
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0xA.Fp-10"));
|
2018-12-06 22:16:16 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.2p-10f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.2p+10F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.2p+10l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0x1.2p+10L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloatHex("0X.2p-0"));
|
2015-07-26 08:06:56 +02:00
|
|
|
|
2018-12-06 22:16:16 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex(""));
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0xa"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("+0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("-0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x"));
|
2015-07-26 12:00:42 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0XP"));
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0xx"));
|
2018-12-06 22:16:16 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x1P+-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x1p+10e"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x1p+1af"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isFloatHex("0x1p+10LL"));
|
2015-07-26 08:06:56 +02:00
|
|
|
}
|
|
|
|
|
2015-07-26 19:21:53 +02:00
|
|
|
void isIntHex() const {
|
2014-03-11 20:02:04 +01:00
|
|
|
// hex number syntax: [sign]0x[hexnumbers][suffix]
|
|
|
|
|
|
|
|
// positive testing
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("0xa"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("0x2AF3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0xa"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x2AF3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0xa"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x2AF3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("0x0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0LL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0LL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("+0x0LLU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isIntHex("-0x0LLU"));
|
2014-03-11 20:02:04 +01:00
|
|
|
|
|
|
|
// negative testing
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("0x"));
|
2018-12-19 14:39:04 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("0xl"));
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("0xx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0175"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0_garbage_"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex(" "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex(" "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0Z"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0Z"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0Uz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0Uz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0Lz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0Lz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0LUz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0LUz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0ULz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0ULz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0LLz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0LLz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0ULLz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0ULLz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+0x0LLUz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("-0x0LLUz"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("0x0+0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("e2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex("+E2"));
|
2014-03-11 20:02:04 +01:00
|
|
|
|
|
|
|
// test empty string
|
2015-07-26 08:06:56 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isIntHex(""));
|
2014-03-11 20:02:04 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 15:25:19 +02:00
|
|
|
void isValidIntegerSuffix() const {
|
2014-11-20 10:23:09 +01:00
|
|
|
// negative testing
|
2018-12-20 12:20:31 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix(""));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("ux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("ulx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("lx"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("lux"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("lll"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("garbage"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("llu "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("iX"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i6X"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i64X"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i64 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i66"));
|
2014-11-20 10:23:09 +01:00
|
|
|
|
|
|
|
// positive testing
|
2018-12-20 12:20:31 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("u"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("ul"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("ull"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("lu"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("ll"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("llu"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("llU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("LLU"));
|
|
|
|
// Microsoft extensions:
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("i64"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("I64"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("ui64"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isValidIntegerSuffix("UI64"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("i64", false));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("I64", false));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("ui64", false));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isValidIntegerSuffix("UI64", false));
|
2014-11-20 10:23:09 +01:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void ispositive() const {
|
2013-09-29 15:11:09 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("-1."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("-1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("-1.0E+2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("-1.0E-2"));
|
|
|
|
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isPositive("+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isPositive("+1."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isPositive("+1.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isPositive("+1.0E+2"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isPositive("+1.0E-2"));
|
2014-03-16 11:55:44 +01:00
|
|
|
|
|
|
|
// test empty string
|
2015-07-26 19:21:53 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isPositive("")); // "" is neither positive nor negative
|
2013-09-29 15:11:09 +02:00
|
|
|
}
|
|
|
|
|
2015-07-26 19:21:53 +02:00
|
|
|
void isFloat() const {
|
2015-07-26 19:47:27 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isFloat(""));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isFloat("0.f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloat("0.f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isFloat("0xA.Fp-10"));
|
2015-07-26 19:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void isDecimalFloat() const {
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(""));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("..."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(".e"));
|
2018-12-10 12:10:26 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(".e2"));
|
2015-07-26 19:21:53 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(".E"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+E."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+e."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-E."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-e."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-X"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+X"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(" "));
|
|
|
|
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("0 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(" 0 "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(" 0"));
|
|
|
|
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.L"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("0. "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(" 0. "));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat(" 0."));
|
|
|
|
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("0.."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("..0.."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("..0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.0f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.0F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.0l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0E+0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0E+0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0.0E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+0.0E-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0.0E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-0.0E-1"));
|
|
|
|
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("-1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1e+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+100"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+100f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+100F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+100l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+100L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+007")); // to be sure about #5485
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+001f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+001F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+001l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+001L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1E+10000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-1E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-1E+10000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat(".1250E+04"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-1E-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-1E-10000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1.23e+01"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("+1.23E+01"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1e+x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+X"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+001lX"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+001LX"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+001f2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+001F2"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1e+003x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDecimalFloat("+1E+003X"));
|
|
|
|
|
|
|
|
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.4"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.3f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.3F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.3l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.3L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("0.00004"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.00001f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.00001F"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.00001l"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("2352.00001L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat(".4"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat(".3e2"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("1.0E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("1.0E-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDecimalFloat("-1.0E+1"));
|
2010-04-02 07:32:03 +02:00
|
|
|
}
|
2013-07-19 09:27:33 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void naninf() const {
|
2013-11-04 11:56:43 +01:00
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.0")); // nan
|
2014-05-16 23:01:21 +02:00
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("-0.0", "0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("-0.f", "0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("-0.0", "-0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("-.0", "-0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "-0.f")); // nan (#5875)
|
|
|
|
ASSERT_EQUALS("nan.0", MathLib::divide("0.f", "-0.f")); // nan (#5875)
|
2013-07-19 09:27:33 +02:00
|
|
|
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.0")); // inf
|
2014-05-16 23:01:21 +02:00
|
|
|
ASSERT_EQUALS("inf.0", MathLib::divide("3.0", "0.f")); // inf (#5875)
|
2013-11-02 22:58:23 +01:00
|
|
|
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0")); // -inf (#5142)
|
2014-05-16 23:01:21 +02:00
|
|
|
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "0.0f")); // -inf (#5142)
|
2015-07-15 17:36:41 +02:00
|
|
|
ASSERT_EQUALS("-inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142)
|
2013-07-19 09:27:33 +02:00
|
|
|
}
|
2014-11-14 21:43:37 +01:00
|
|
|
|
2019-09-25 15:25:19 +02:00
|
|
|
void isdec() const {
|
2014-11-14 04:29:35 +01:00
|
|
|
// positive testing
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("-100"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("-1L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isDec("1UL"));
|
|
|
|
|
|
|
|
// negative testing
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDec("-1."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDec("+1."));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDec("-x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDec("+x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isDec("x"));
|
2018-12-10 12:10:26 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isDec(""));
|
2014-11-14 21:43:37 +01:00
|
|
|
}
|
2014-04-11 01:27:05 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void isNullValue() const {
|
2014-04-11 01:27:05 +02:00
|
|
|
// inter zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0"));
|
|
|
|
// inter zero value (octal)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00"));
|
|
|
|
// inter zero value (hex)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0x0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0x0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0x0"));
|
2020-02-02 16:40:36 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0X0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0X0"));
|
2014-04-11 01:27:05 +02:00
|
|
|
// unsigned integer zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0U"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0U"));
|
|
|
|
// long integer zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0L"));
|
|
|
|
// unsigned long integer zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0UL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0UL"));
|
|
|
|
// unsigned long integer zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0LU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0LU"));
|
|
|
|
// long long integer zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0LL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0LL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0LL"));
|
2015-01-14 00:51:50 +01:00
|
|
|
// long long unsigned zero value
|
2014-04-11 01:27:05 +02:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0LLU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0LLU"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0LLU"));
|
|
|
|
// unsigned long long zero value
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0ULL"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0ULL"));
|
|
|
|
// floating pointer zero value (no trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0."));
|
|
|
|
// floating pointer zero value (1 trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.0"));
|
|
|
|
// floating pointer zero value (3 trailing zeros after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.000"));
|
|
|
|
// floating pointer zero value (no trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00."));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00."));
|
|
|
|
// floating pointer zero value (1 trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00.0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00.0"));
|
|
|
|
// floating pointer zero value (3 trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00.000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00.000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00.000"));
|
|
|
|
// floating pointer zero value (3 trailing zero after dot)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue(".000"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E0"));
|
2020-02-02 16:40:36 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0e0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0e0"));
|
2014-04-11 01:27:05 +02:00
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E1"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E42"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E429999"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E+1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E+1"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E+42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E+42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E+42"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E+429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E+429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E+429999"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E-1"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E-1"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E-42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E-42"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E-42"));
|
|
|
|
// integer scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0E-429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0E-429999"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0E-429999"));
|
|
|
|
// floating point scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.E0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.E0"));
|
|
|
|
// floating point scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.E+0"));
|
|
|
|
// floating point scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.E+0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.E+0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.E+0"));
|
|
|
|
// floating point scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.00E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.00E-0"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.00E-0"));
|
|
|
|
// floating point scientific notation
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00000.00E-000000000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00000.00E-000000000"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00000.00E-000000000"));
|
|
|
|
// floating point scientific notation (suffix f)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.f"));
|
|
|
|
// floating point scientific notation (suffix f)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.0f"));
|
2020-02-02 16:40:36 +01:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0.0F"));
|
2014-04-11 01:27:05 +02:00
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0.0f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0.0f"));
|
|
|
|
// floating point scientific notation (suffix f)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00.0f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00.0f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00.0f"));
|
|
|
|
// floating point scientific notation (suffix f)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00.00f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00.00f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00.00f"));
|
|
|
|
// floating point scientific notation (suffix f)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("00.00E+1f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+00.00E+1f"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-00.00E+1f"));
|
2020-02-02 16:40:36 +01:00
|
|
|
// hex float
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0x0p3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0X0P3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0X0p-3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0x0p3"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0x0p3"));
|
2014-04-11 01:27:05 +02:00
|
|
|
|
2014-04-12 02:14:50 +02:00
|
|
|
// binary numbers
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0b00"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0b00"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0b00"));
|
|
|
|
// binary numbers (long)
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("0b00L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("+0b00L"));
|
|
|
|
ASSERT_EQUALS(true, MathLib::isNullValue("-0b00L"));
|
2014-04-11 01:27:05 +02:00
|
|
|
// negative testing
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0.1"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("1.0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0.01"));
|
2020-02-02 16:40:36 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xF"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0XFF"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0b01"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0B01"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0x1p0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0x1P0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xap0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xbp0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xcp0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xdp0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xep0"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("0xfp0"));
|
2014-04-11 01:27:05 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("-00.01e-12"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("-00.01e+12"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue(""));
|
2014-04-14 05:27:38 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue(" "));
|
2014-04-11 01:27:05 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("x"));
|
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("garbage"));
|
2014-04-12 02:14:50 +02:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("UL"));
|
2020-02-09 11:16:08 +01:00
|
|
|
ASSERT_EQUALS(false, MathLib::isNullValue("-ENOMEM"));
|
2014-04-11 01:27:05 +02:00
|
|
|
}
|
2014-05-29 18:25:01 +02:00
|
|
|
|
2015-01-19 18:00:05 +01:00
|
|
|
void incdec() const {
|
2014-05-29 18:25:01 +02:00
|
|
|
// increment
|
|
|
|
{
|
2018-09-24 15:08:16 +02:00
|
|
|
const MathLib::biguint num = ~10U;
|
2014-05-29 18:25:01 +02:00
|
|
|
const std::string op = "++";
|
|
|
|
const std::string strNum = MathLib::incdec(MathLib::toString(num), op);
|
|
|
|
const MathLib::biguint incrementedNum = MathLib::toULongNumber(strNum);
|
|
|
|
ASSERT_EQUALS(num + 1U, incrementedNum);
|
|
|
|
}
|
|
|
|
// decrement
|
|
|
|
{
|
2018-09-24 15:08:16 +02:00
|
|
|
const MathLib::biguint num = ~10U;
|
2014-05-29 18:25:01 +02:00
|
|
|
const std::string op = "--";
|
|
|
|
const std::string strNum = MathLib::incdec(MathLib::toString(num), op);
|
|
|
|
const MathLib::biguint decrementedNum = MathLib::toULongNumber(strNum);
|
|
|
|
ASSERT_EQUALS(num - 1U, decrementedNum);
|
|
|
|
}
|
2014-06-04 08:41:30 +02:00
|
|
|
// invalid operation
|
|
|
|
ASSERT_THROW(MathLib::incdec("1", "x"), InternalError); // throw
|
2014-05-29 18:25:01 +02:00
|
|
|
}
|
2014-11-16 18:09:21 +01:00
|
|
|
|
2015-01-19 18:00:05 +01:00
|
|
|
void sin() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0.0", MathLib::sin("0"));
|
2014-11-16 18:09:21 +01:00
|
|
|
}
|
2015-01-19 18:00:05 +01:00
|
|
|
void cos() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("1.0", MathLib::cos("0"));
|
2014-11-16 18:09:21 +01:00
|
|
|
}
|
2015-01-19 18:00:05 +01:00
|
|
|
void tan() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0.0", MathLib::tan("0"));
|
2014-11-16 18:09:21 +01:00
|
|
|
}
|
2015-01-19 18:00:05 +01:00
|
|
|
void abs() const {
|
2020-02-19 07:51:39 +01:00
|
|
|
ASSERT_EQUALS("", MathLib::abs(""));
|
|
|
|
ASSERT_EQUALS("0", MathLib::abs("0"));
|
|
|
|
ASSERT_EQUALS("+0", MathLib::abs("+0"));
|
|
|
|
ASSERT_EQUALS("0", MathLib::abs("-0"));
|
|
|
|
ASSERT_EQUALS("+1", MathLib::abs("+1"));
|
|
|
|
ASSERT_EQUALS("+1.0", MathLib::abs("+1.0"));
|
|
|
|
ASSERT_EQUALS("1", MathLib::abs("-1"));
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("1.0", MathLib::abs("-1.0"));
|
2020-02-19 07:51:39 +01:00
|
|
|
ASSERT_EQUALS("9007199254740991", MathLib::abs("9007199254740991"));
|
2014-11-16 18:09:21 +01:00
|
|
|
}
|
2014-12-03 18:24:27 +01:00
|
|
|
|
2015-01-19 18:00:05 +01:00
|
|
|
void toString() const {
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(0.0));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(+0.0));
|
|
|
|
ASSERT_EQUALS("0.0", MathLib::toString(-0.0));
|
2014-12-03 18:24:27 +01:00
|
|
|
// float (trailing f or F)
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0", MathLib::toString(+0.0f));
|
|
|
|
ASSERT_EQUALS("-0", MathLib::toString(-0.0F));
|
2014-12-03 18:24:27 +01:00
|
|
|
// double (tailing l or L)
|
2018-01-08 20:20:33 +01:00
|
|
|
ASSERT_EQUALS("0", MathLib::toString(+0.0l));
|
|
|
|
ASSERT_EQUALS("-0", MathLib::toString(-0.0L));
|
2014-12-03 18:24:27 +01:00
|
|
|
}
|
2016-05-15 15:48:24 +02:00
|
|
|
|
2017-01-07 14:13:22 +01:00
|
|
|
void CPP14DigitSeparators() const { // Ticket #7137, #7565
|
2016-06-04 22:55:55 +02:00
|
|
|
ASSERT(MathLib::isDigitSeparator("'", 0) == false);
|
|
|
|
ASSERT(MathLib::isDigitSeparator("123'0;", 3));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("foo(1'2);", 5));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("foo(1,1'2);", 7));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("int a=1'234-1'2-'0';", 7));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("int a=1'234-1'2-'0';", 13));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("int a=1'234-1'2-'0';", 16) == false);
|
|
|
|
ASSERT(MathLib::isDigitSeparator("int b=1+9'8;", 9));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (1'2) { char c = 'c'; }", 5));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (120%1'2) { char c = 'c'; }", 9));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (120&1'2) { char c = 'c'; }", 9));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (120|1'2) { char c = 'c'; }", 9));
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (120%1'2) { char c = 'c'; }", 24) == false);
|
|
|
|
ASSERT(MathLib::isDigitSeparator("if (120%1'2) { char c = 'c'; }", 26) == false);
|
2016-07-01 23:22:16 +02:00
|
|
|
ASSERT(MathLib::isDigitSeparator("0b0000001'0010'01110", 14));
|
2016-06-04 22:55:55 +02:00
|
|
|
}
|
2009-04-06 19:08:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestMathLib)
|