astyle formatting
This commit is contained in:
parent
1c0f3ee179
commit
24c5f4d53c
|
@ -33,14 +33,14 @@
|
|||
long MathLib::toLongNumber(const std::string &str)
|
||||
{
|
||||
if (strncmp(str.c_str(), "0x" , 2) == 0
|
||||
||strncmp(str.c_str(), "+0x", 3) == 0
|
||||
||strncmp(str.c_str(), "-0x", 3) == 0)
|
||||
|| strncmp(str.c_str(), "+0x", 3) == 0
|
||||
|| strncmp(str.c_str(), "-0x", 3) == 0)
|
||||
{
|
||||
return std::strtoul(str.c_str(), '\0', 16);
|
||||
}
|
||||
if (strncmp(str.c_str(), "0" , 1) == 0
|
||||
|| strncmp(str.c_str(), "+0", 2) == 0
|
||||
|| strncmp(str.c_str(), "-0", 2) == 0)
|
||||
if (strncmp(str.c_str(), "0" , 1) == 0
|
||||
|| strncmp(str.c_str(), "+0", 2) == 0
|
||||
|| strncmp(str.c_str(), "-0", 2) == 0)
|
||||
{
|
||||
return std::strtoul(str.c_str(), '\0', 8);
|
||||
}
|
||||
|
@ -66,12 +66,12 @@ std::string MathLib::toString(T d)
|
|||
{
|
||||
std::ostringstream result;
|
||||
result << d;
|
||||
std::string strResult(result.str());
|
||||
if(strResult == "-0"
|
||||
|| strResult == "+0"
|
||||
|| strResult == "-0."
|
||||
|| strResult == "+0.")
|
||||
return std::string("0");
|
||||
std::string strResult(result.str());
|
||||
if (strResult == "-0"
|
||||
|| strResult == "+0"
|
||||
|| strResult == "-0."
|
||||
|| strResult == "+0.")
|
||||
return std::string("0");
|
||||
return result.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ private:
|
|||
|
||||
void calculate()
|
||||
{
|
||||
// addition
|
||||
// addition
|
||||
ASSERT_EQUALS("256", MathLib::add("0xff", "1"));
|
||||
ASSERT_EQUALS("249", MathLib::add("250", "-1"));
|
||||
ASSERT_EQUALS("251", MathLib::add("250", "1"));
|
||||
|
@ -47,7 +47,7 @@ private:
|
|||
ASSERT_EQUALS("1" , MathLib::add("1", "0"));
|
||||
ASSERT_EQUALS("0" , MathLib::add("0", "0."));
|
||||
|
||||
// subtraction
|
||||
// subtraction
|
||||
ASSERT_EQUALS("254", MathLib::subtract("0xff", "1"));
|
||||
ASSERT_EQUALS("251", MathLib::subtract("250", "-1"));
|
||||
ASSERT_EQUALS("249", MathLib::subtract("250", "1"));
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
ASSERT_EQUALS("1" , MathLib::subtract("1", "0"));
|
||||
ASSERT_EQUALS("0" , MathLib::subtract("0", "0."));
|
||||
|
||||
// multiply
|
||||
// multiply
|
||||
ASSERT_EQUALS("-0.003", MathLib::multiply("-1e-3", "3"));
|
||||
ASSERT_EQUALS("-11.96", MathLib::multiply("-2.3", "5.2"));
|
||||
ASSERT_EQUALS("3000" , MathLib::multiply("1E3", "3"));
|
||||
|
@ -67,12 +67,12 @@ private:
|
|||
ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0"));
|
||||
ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0"));
|
||||
|
||||
// divide
|
||||
// divide
|
||||
ASSERT_EQUALS("1" , MathLib::divide("1", "1"));
|
||||
ASSERT_EQUALS("0" , MathLib::divide("0", "1"));
|
||||
ASSERT_EQUALS("5" , MathLib::divide("-10", "-2"));
|
||||
ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4"));
|
||||
ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4"));
|
||||
ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4"));
|
||||
ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1"));
|
||||
ASSERT_EQUALS("7" , MathLib::divide("21.", "3"));
|
||||
ASSERT_EQUALS("1" , MathLib::divide("3", "2"));
|
||||
|
@ -81,11 +81,11 @@ private:
|
|||
|
||||
void convert()
|
||||
{
|
||||
// ------------------
|
||||
// tolong conversion:
|
||||
// ------------------
|
||||
// ------------------
|
||||
// tolong conversion:
|
||||
// ------------------
|
||||
|
||||
// from hex
|
||||
// from hex
|
||||
ASSERT_EQUALS(10 , MathLib::toLongNumber("0xa"));
|
||||
ASSERT_EQUALS(10995 , MathLib::toLongNumber("0x2AF3"));
|
||||
ASSERT_EQUALS(-10 , MathLib::toLongNumber("-0xa"));
|
||||
|
@ -93,7 +93,7 @@ private:
|
|||
ASSERT_EQUALS(10 , MathLib::toLongNumber("+0xa"));
|
||||
ASSERT_EQUALS(10995 , MathLib::toLongNumber("+0x2AF3"));
|
||||
|
||||
// from octal
|
||||
// from octal
|
||||
ASSERT_EQUALS(8 , MathLib::toLongNumber("010"));
|
||||
ASSERT_EQUALS(8 , MathLib::toLongNumber("+010"));
|
||||
ASSERT_EQUALS(-8 , MathLib::toLongNumber("-010"));
|
||||
|
@ -101,7 +101,7 @@ private:
|
|||
ASSERT_EQUALS(125 , MathLib::toLongNumber("+0175"));
|
||||
ASSERT_EQUALS(-125 , MathLib::toLongNumber("-0175"));
|
||||
|
||||
// from base 10
|
||||
// from base 10
|
||||
ASSERT_EQUALS(10 , MathLib::toLongNumber("10"));
|
||||
ASSERT_EQUALS(10 , MathLib::toLongNumber("10."));
|
||||
ASSERT_EQUALS(10 , MathLib::toLongNumber("10.0"));
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
|
||||
void isint()
|
||||
{
|
||||
// zero tests
|
||||
// zero tests
|
||||
ASSERT_EQUALS(true , MathLib::isInt("0"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("0."));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("0.0"));
|
||||
|
@ -130,16 +130,16 @@ private:
|
|||
ASSERT_EQUALS(false, MathLib::isInt("-0.0E+1"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("-0.0E-1"));
|
||||
|
||||
ASSERT_EQUALS(true , MathLib::isInt("1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("-1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("-1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("+1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("+1E+1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("+1E+10000"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("-1E+1"));
|
||||
ASSERT_EQUALS(true , MathLib::isInt("-1E+10000"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("-1E-1"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("-1E-10000"));
|
||||
|
||||
ASSERT_EQUALS(false, MathLib::isInt("-1E-10000"));
|
||||
|
||||
ASSERT_EQUALS(true, MathLib::isInt("0xff"));
|
||||
ASSERT_EQUALS(true, MathLib::isInt("0xa"));
|
||||
ASSERT_EQUALS(true, MathLib::isInt("0l"));
|
||||
|
|
Loading…
Reference in New Issue