📄 tuplestest.cpp.svn-base
字号:
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 10);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple11()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string> TupleType;
TupleType aTuple;
assert (aTuple.length == 11);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1");
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple12()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 12);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple13()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool> TupleType;
TupleType aTuple;
assert (aTuple.length == 13);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple14()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float> TupleType;
TupleType aTuple;
assert (aTuple.length == 14);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple15()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char> TupleType;
TupleType aTuple;
assert (aTuple.length == 15);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c');
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple16()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long> TupleType;
TupleType aTuple;
assert (aTuple.length == 16);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple17()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double> TupleType;
TupleType aTuple;
assert (aTuple.length == 17);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple18()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short> TupleType;
TupleType aTuple;
assert (aTuple.length == 18);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple19()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short, std::string> TupleType;
TupleType aTuple;
assert (aTuple.length == 19);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2");
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple20()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 20);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTupleOrder()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 20);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
TupleType aTuple3;
aTuple3 = aTuple2;
aTuple3.get<1>()++;
assert (aTuple2 < aTuple3);
testTupleStrictWeak(aTuple, aTuple2, aTuple3);
std::vector<TupleType> tv;
tv.push_back(aTuple3);
tv.push_back(aTuple);
tv.push_back(aTuple2);
assert (tv[0] == aTuple3);
assert (tv[1] == aTuple);
assert (tv[2] == aTuple2);
std::sort(tv.begin(), tv.end());
assert (tv[0] == aTuple);
assert (tv[1] == aTuple2);
assert (tv[2] == aTuple3);
std::map<TupleType, int> tm;
std::pair<std::map<TupleType, int>::iterator, bool> mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple2, 2));
assert (mIt.second);
mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple, 1));
assert (mIt.second);
mIt = tm.insert(std::map<TupleType, int>::value_type(aTuple3, 3));
assert (mIt.second);
std::map<TupleType, int>::iterator fIt = tm.find(aTuple2);
assert (2 == fIt->second);
typedef Tuple<std::string, std::string, std::string, std::string> StrTup;
typedef std::map<StrTup, int> StrTupMap;
StrTup st1("123", "456", "789", "101112");
StrTup st2("123", "456", "101112", "789");
StrTup st3("123", "789", "789", "101112");
StrTup st4("123", "101112", "456", "789");
testTupleStrictWeak(st2, st1, st3);
StrTupMap strMap;
strMap.insert(StrTupMap::value_type(st1, 1));
strMap.insert(StrTupMap::value_type(st2, 2));
strMap.insert(StrTupMap::value_type(st3, 3));
strMap.insert(StrTupMap::value_type(st4, 4));
assert (1 == strMap[st1]);
assert (2 == strMap[st2]);
assert (3 == strMap[st3]);
assert (4 == strMap[st4]);
StrTupMap::iterator it = strMap.begin();
assert (st4 == it->first); ++it;
assert (st2 == it->first); ++it;
assert (st1 == it->first); ++it;
assert (st3 == it->first); ++it;
assert (it == strMap.end());
}
void TuplesTest::testMemOverhead()
{
Tuple<short> small(0);
int sz = sizeof(small);
assert (sz == 4 || sz == 8); //depending on architecture and alignment
Tuple<long> notSoSmall(0);
sz = sizeof(notSoSmall);
assert (sz == 8 || sz == 16); //depending on architecture and alignment
}
void TuplesTest::setUp()
{
}
void TuplesTest::tearDown()
{
}
CppUnit::Test* TuplesTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TuplesTest");
CppUnit_addTest(pSuite, TuplesTest, testTuple1);
CppUnit_addTest(pSuite, TuplesTest, testTuple2);
CppUnit_addTest(pSuite, TuplesTest, testTuple3);
CppUnit_addTest(pSuite, TuplesTest, testTuple4);
CppUnit_addTest(pSuite, TuplesTest, testTuple5);
CppUnit_addTest(pSuite, TuplesTest, testTuple6);
CppUnit_addTest(pSuite, TuplesTest, testTuple7);
CppUnit_addTest(pSuite, TuplesTest, testTuple8);
CppUnit_addTest(pSuite, TuplesTest, testTuple9);
CppUnit_addTest(pSuite, TuplesTest, testTuple10);
CppUnit_addTest(pSuite, TuplesTest, testTuple11);
CppUnit_addTest(pSuite, TuplesTest, testTuple12);
CppUnit_addTest(pSuite, TuplesTest, testTuple13);
CppUnit_addTest(pSuite, TuplesTest, testTuple14);
CppUnit_addTest(pSuite, TuplesTest, testTuple15);
CppUnit_addTest(pSuite, TuplesTest, testTuple16);
CppUnit_addTest(pSuite, TuplesTest, testTuple17);
CppUnit_addTest(pSuite, TuplesTest, testTuple18);
CppUnit_addTest(pSuite, TuplesTest, testTuple19);
CppUnit_addTest(pSuite, TuplesTest, testTuple20);
CppUnit_addTest(pSuite, TuplesTest, testTupleOrder);
CppUnit_addTest(pSuite, TuplesTest, testMemOverhead);
return pSuite;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -