Unit test framework.

This commit is contained in:
JoelKatz
2012-04-12 23:41:32 -07:00
parent 9f58a4bfbf
commit f5464e02b6
2 changed files with 65 additions and 0 deletions

View File

@@ -326,3 +326,66 @@ STAmount convertToInternalAmount(const STAmount& displayAmount, const STAmount&
{ // Convert a display/request currency amount to an internal amount
return (displayAmount * totalNow) / totalInit;
}
void STAmount::unitTest()
{
STAmount zero, one(1), hundred(100);
if (!zero.isZero()) throw std::runtime_error("STAmount fail");
if (one.isZero()) throw std::runtime_error("STAmount fail");
if (hundred.isZero()) throw std::runtime_error("STAmount fail");
if ((zero < zero)) throw std::runtime_error("STAmount fail");
if (!(zero < one)) throw std::runtime_error("STAmount fail");
if (!(zero < hundred)) throw std::runtime_error("STAmount fail");
if ((one < zero)) throw std::runtime_error("STAmount fail");
if ((one < one)) throw std::runtime_error("STAmount fail");
if (!(one < hundred)) throw std::runtime_error("STAmount fail");
if ((hundred < zero)) throw std::runtime_error("STAmount fail");
if ((hundred < one)) throw std::runtime_error("STAmount fail");
if ((hundred < hundred)) throw std::runtime_error("STAmount fail");
if ((zero > zero)) throw std::runtime_error("STAmount fail");
if ((zero > one)) throw std::runtime_error("STAmount fail");
if ((zero > hundred)) throw std::runtime_error("STAmount fail");
if (!(one > zero)) throw std::runtime_error("STAmount fail");
if ((one > one)) throw std::runtime_error("STAmount fail");
if ((one > hundred)) throw std::runtime_error("STAmount fail");
if (!(hundred > zero)) throw std::runtime_error("STAmount fail");
if (!(hundred > one)) throw std::runtime_error("STAmount fail");
if ((hundred > hundred)) throw std::runtime_error("STAmount fail");
if (!(zero <= zero)) throw std::runtime_error("STAmount fail");
if (!(zero <= one)) throw std::runtime_error("STAmount fail");
if (!(zero <= hundred)) throw std::runtime_error("STAmount fail");
if ((one <= zero)) throw std::runtime_error("STAmount fail");
if (!(one <= one)) throw std::runtime_error("STAmount fail");
if (!(one <= hundred)) throw std::runtime_error("STAmount fail");
if ((hundred <= zero)) throw std::runtime_error("STAmount fail");
if ((hundred <= one)) throw std::runtime_error("STAmount fail");
if (!(hundred <= hundred)) throw std::runtime_error("STAmount fail");
if (!(zero >= zero)) throw std::runtime_error("STAmount fail");
if ((zero >= one)) throw std::runtime_error("STAmount fail");
if ((zero >= hundred)) throw std::runtime_error("STAmount fail");
if (!(one >= zero)) throw std::runtime_error("STAmount fail");
if (!(one >= one)) throw std::runtime_error("STAmount fail");
if ((one >= hundred)) throw std::runtime_error("STAmount fail");
if (!(hundred >= zero)) throw std::runtime_error("STAmount fail");
if (!(hundred >= one)) throw std::runtime_error("STAmount fail");
if (!(hundred >= hundred)) throw std::runtime_error("STAmount fail");
if (!(zero == zero)) throw std::runtime_error("STAmount fail");
if ((zero == one)) throw std::runtime_error("STAmount fail");
if ((zero == hundred)) throw std::runtime_error("STAmount fail");
if ((one == zero)) throw std::runtime_error("STAmount fail");
if (!(one == one)) throw std::runtime_error("STAmount fail");
if ((one == hundred)) throw std::runtime_error("STAmount fail");
if ((hundred == zero)) throw std::runtime_error("STAmount fail");
if ((hundred == one)) throw std::runtime_error("STAmount fail");
if (!(hundred == hundred)) throw std::runtime_error("STAmount fail");
if ((zero != zero)) throw std::runtime_error("STAmount fail");
if (!(zero != one)) throw std::runtime_error("STAmount fail");
if (!(zero != hundred)) throw std::runtime_error("STAmount fail");
if (!(one != zero)) throw std::runtime_error("STAmount fail");
if ((one != one)) throw std::runtime_error("STAmount fail");
if (!(one != hundred)) throw std::runtime_error("STAmount fail");
if (!(hundred != zero)) throw std::runtime_error("STAmount fail");
if (!(hundred != one)) throw std::runtime_error("STAmount fail");
if ((hundred != hundred)) throw std::runtime_error("STAmount fail");
}

View File

@@ -237,6 +237,8 @@ public:
const STAmount& totalNow, const STAmount& totalInit);
friend STAmount convertToInternalAmount(const STAmount& displayAmount,
const STAmount& totalNow, const STAmount& totalInit);
static void unitTest();
};
class STHash128 : public SerializedType