Added new test structures that allow for nonfatal assertions: EXPECT, EXPECT_DOUBLES_EQUAL, EXPECT_LONGS_EQUAL. Use these to check several unrelated conditions in a test. testTupleConfig was updated to make use of the new test structures.
parent
99e4c09a7e
commit
3dfbb26bc7
|
@ -54,8 +54,20 @@ protected:
|
||||||
testGroup##testName##Instance; \
|
testGroup##testName##Instance; \
|
||||||
void testGroup##testName##Test::run (TestResult& result_)
|
void testGroup##testName##Test::run (TestResult& result_)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convention for tests:
|
||||||
|
* - "EXPECT" is a test that will not end execution of the series of tests
|
||||||
|
* - Otherwise, upon a failure, the test will end
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* EXPECT is useful when checking several different parts of an condition so
|
||||||
|
* that a failure of one check won't hide another failure.
|
||||||
|
*
|
||||||
|
* Note: Exception tests are not available in a EXPECT form, as exceptions rarely
|
||||||
|
* fit the criteria of an assertion that does not need to be true to continue
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* True ASSERTs: tests end at first failure */
|
||||||
#define CHECK(condition)\
|
#define CHECK(condition)\
|
||||||
{ if (!(condition)) \
|
{ if (!(condition)) \
|
||||||
{ result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); return; } }
|
{ result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); return; } }
|
||||||
|
@ -78,7 +90,6 @@ protected:
|
||||||
#define CHECK_EQUAL(expected,actual)\
|
#define CHECK_EQUAL(expected,actual)\
|
||||||
{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
|
{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); }
|
||||||
|
|
||||||
|
|
||||||
#define LONGS_EQUAL(expected,actual)\
|
#define LONGS_EQUAL(expected,actual)\
|
||||||
{ long actualTemp = actual; \
|
{ long actualTemp = actual; \
|
||||||
long expectedTemp = expected; \
|
long expectedTemp = expected; \
|
||||||
|
@ -86,8 +97,6 @@ protected:
|
||||||
{ result_.addFailure (Failure (name_, __FILE__, __LINE__, StringFrom(expectedTemp), \
|
{ result_.addFailure (Failure (name_, __FILE__, __LINE__, StringFrom(expectedTemp), \
|
||||||
StringFrom(actualTemp))); return; } }
|
StringFrom(actualTemp))); return; } }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DOUBLES_EQUAL(expected,actual,threshold)\
|
#define DOUBLES_EQUAL(expected,actual,threshold)\
|
||||||
{ double actualTemp = actual; \
|
{ double actualTemp = actual; \
|
||||||
double expectedTemp = expected; \
|
double expectedTemp = expected; \
|
||||||
|
@ -96,6 +105,25 @@ StringFrom(actualTemp))); return; } }
|
||||||
StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); return; } }
|
StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); return; } }
|
||||||
|
|
||||||
|
|
||||||
|
/* EXPECTs: tests will continue running after a failure */
|
||||||
|
#define EXPECT(condition)\
|
||||||
|
{ if (!(condition)) \
|
||||||
|
{ result_.addFailure (Failure (name_, __FILE__,__LINE__, #condition)); } }
|
||||||
|
|
||||||
|
#define EXPECT_LONGS_EQUAL(expected,actual)\
|
||||||
|
{ long actualTemp = actual; \
|
||||||
|
long expectedTemp = expected; \
|
||||||
|
if ((expectedTemp) != (actualTemp)) \
|
||||||
|
{ result_.addFailure (Failure (name_, __FILE__, __LINE__, StringFrom(expectedTemp), \
|
||||||
|
StringFrom(actualTemp))); } }
|
||||||
|
|
||||||
|
#define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\
|
||||||
|
{ double actualTemp = actual; \
|
||||||
|
double expectedTemp = expected; \
|
||||||
|
if (fabs ((expectedTemp)-(actualTemp)) > threshold) \
|
||||||
|
{ result_.addFailure (Failure (name_, __FILE__, __LINE__, \
|
||||||
|
StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); } }
|
||||||
|
|
||||||
|
|
||||||
#define FAIL(text) \
|
#define FAIL(text) \
|
||||||
{ result_.addFailure (Failure (name_, __FILE__, __LINE__,(text))); return; }
|
{ result_.addFailure (Failure (name_, __FILE__, __LINE__,(text))); return; }
|
||||||
|
|
|
@ -125,8 +125,8 @@ TEST( TupleConfig, size_dim )
|
||||||
config1.insert(PointKey(1), l1);
|
config1.insert(PointKey(1), l1);
|
||||||
config1.insert(PointKey(2), l2);
|
config1.insert(PointKey(2), l2);
|
||||||
|
|
||||||
CHECK(config1.size() == 4);
|
EXPECT(config1.size() == 4);
|
||||||
CHECK(config1.dim() == 10);
|
EXPECT(config1.dim() == 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -141,10 +141,10 @@ TEST(TupleConfig, at)
|
||||||
config1.insert(PointKey(1), l1);
|
config1.insert(PointKey(1), l1);
|
||||||
config1.insert(PointKey(2), l2);
|
config1.insert(PointKey(2), l2);
|
||||||
|
|
||||||
CHECK(assert_equal(x1, config1[PoseKey(1)]));
|
EXPECT(assert_equal(x1, config1[PoseKey(1)]));
|
||||||
CHECK(assert_equal(x2, config1[PoseKey(2)]));
|
EXPECT(assert_equal(x2, config1[PoseKey(2)]));
|
||||||
CHECK(assert_equal(l1, config1[PointKey(1)]));
|
EXPECT(assert_equal(l1, config1[PointKey(1)]));
|
||||||
CHECK(assert_equal(l2, config1[PointKey(2)]));
|
EXPECT(assert_equal(l2, config1[PointKey(2)]));
|
||||||
|
|
||||||
CHECK_EXCEPTION(config1[PoseKey(3)], std::invalid_argument);
|
CHECK_EXCEPTION(config1[PoseKey(3)], std::invalid_argument);
|
||||||
CHECK_EXCEPTION(config1[PointKey(3)], std::invalid_argument);
|
CHECK_EXCEPTION(config1[PointKey(3)], std::invalid_argument);
|
||||||
|
@ -233,33 +233,33 @@ TEST(TupleConfig, basic_functions) {
|
||||||
configB.insert(L1, lam1);
|
configB.insert(L1, lam1);
|
||||||
|
|
||||||
// bracket operator
|
// bracket operator
|
||||||
CHECK(assert_equal(configA[x1], pose1));
|
EXPECT(assert_equal(configA[x1], pose1));
|
||||||
CHECK(assert_equal(configA[l1], point1));
|
EXPECT(assert_equal(configA[l1], point1));
|
||||||
CHECK(assert_equal(configB[x1], pose1));
|
EXPECT(assert_equal(configB[x1], pose1));
|
||||||
CHECK(assert_equal(configB[l1], point1));
|
EXPECT(assert_equal(configB[l1], point1));
|
||||||
CHECK(assert_equal(configB[L1], lam1));
|
EXPECT(assert_equal(configB[L1], lam1));
|
||||||
|
|
||||||
// exists
|
// exists
|
||||||
CHECK(configA.exists(x1));
|
EXPECT(configA.exists(x1));
|
||||||
CHECK(configA.exists(l1));
|
EXPECT(configA.exists(l1));
|
||||||
CHECK(configB.exists(x1));
|
EXPECT(configB.exists(x1));
|
||||||
CHECK(configB.exists(l1));
|
EXPECT(configB.exists(l1));
|
||||||
CHECK(configB.exists(L1));
|
EXPECT(configB.exists(L1));
|
||||||
|
|
||||||
// at
|
// at
|
||||||
CHECK(assert_equal(configA.at(x1), pose1));
|
EXPECT(assert_equal(configA.at(x1), pose1));
|
||||||
CHECK(assert_equal(configA.at(l1), point1));
|
EXPECT(assert_equal(configA.at(l1), point1));
|
||||||
CHECK(assert_equal(configB.at(x1), pose1));
|
EXPECT(assert_equal(configB.at(x1), pose1));
|
||||||
CHECK(assert_equal(configB.at(l1), point1));
|
EXPECT(assert_equal(configB.at(l1), point1));
|
||||||
CHECK(assert_equal(configB.at(L1), lam1));
|
EXPECT(assert_equal(configB.at(L1), lam1));
|
||||||
|
|
||||||
// size
|
// size
|
||||||
CHECK(configA.size() == 2);
|
EXPECT(configA.size() == 2);
|
||||||
CHECK(configB.size() == 3);
|
EXPECT(configB.size() == 3);
|
||||||
|
|
||||||
// dim
|
// dim
|
||||||
CHECK(configA.dim() == 5);
|
EXPECT(configA.dim() == 5);
|
||||||
CHECK(configB.dim() == 6);
|
EXPECT(configB.dim() == 6);
|
||||||
|
|
||||||
// erase
|
// erase
|
||||||
configA.erase(x1);
|
configA.erase(x1);
|
||||||
|
@ -274,13 +274,13 @@ TEST(TupleConfig, basic_functions) {
|
||||||
|
|
||||||
// clear
|
// clear
|
||||||
configA.clear();
|
configA.clear();
|
||||||
CHECK(configA.size() == 0);
|
EXPECT(configA.size() == 0);
|
||||||
configB.clear();
|
configB.clear();
|
||||||
CHECK(configB.size() == 0);
|
EXPECT(configB.size() == 0);
|
||||||
|
|
||||||
// empty
|
// empty
|
||||||
CHECK(configA.empty());
|
EXPECT(configA.empty());
|
||||||
CHECK(configB.empty());
|
EXPECT(configB.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -370,12 +370,12 @@ TEST( TupleConfig, equals )
|
||||||
|
|
||||||
ConfigA config6(config1);
|
ConfigA config6(config1);
|
||||||
|
|
||||||
CHECK(assert_equal(config1,config2));
|
EXPECT(assert_equal(config1,config2));
|
||||||
CHECK(assert_equal(config1,config1));
|
EXPECT(assert_equal(config1,config1));
|
||||||
CHECK(!config1.equals(config3));
|
EXPECT(!config1.equals(config3));
|
||||||
CHECK(!config1.equals(config4));
|
EXPECT(!config1.equals(config4));
|
||||||
CHECK(!config1.equals(config5));
|
EXPECT(!config1.equals(config5));
|
||||||
CHECK(assert_equal(config1, config6));
|
EXPECT(assert_equal(config1, config6));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
Loading…
Reference in New Issue