new functions min and max for 2 - 2+n parameters - now in C++11 vith variadics
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <mrw/checkcxx11.hxx>
|
||||||
|
|
||||||
namespace mrw {
|
namespace mrw {
|
||||||
|
|
||||||
@@ -52,6 +53,11 @@ namespace mrw {
|
|||||||
template<typename T> T& max(T& t1, T& t2) {
|
template<typename T> T& max(T& t1, T& t2) {
|
||||||
return t2<t1?t1:t2;
|
return t2<t1?t1:t2;
|
||||||
}
|
}
|
||||||
|
//! Get the maximum out of two values
|
||||||
|
template<typename T> const T& max(const T& t1, const T& t2) {
|
||||||
|
return t2<t1?t1:t2;
|
||||||
|
}
|
||||||
|
#ifdef MRW__OLD_PRE11_COMPILER
|
||||||
//! Get the maximum out of three values
|
//! Get the maximum out of three values
|
||||||
template<typename T> T& max(T& t1, T& t2, T& t3) {
|
template<typename T> T& max(T& t1, T& t2, T& t3) {
|
||||||
return max(t1, max(t2, t3));
|
return max(t1, max(t2, t3));
|
||||||
@@ -68,10 +74,6 @@ namespace mrw {
|
|||||||
template<typename T> T& max(T& t1, T& t2, T& t3, T& t4, T& t5, T& t6) {
|
template<typename T> T& max(T& t1, T& t2, T& t3, T& t4, T& t5, T& t6) {
|
||||||
return max(max(t1, t2, t3), max(t4, t5, t6));
|
return max(max(t1, t2, t3), max(t4, t5, t6));
|
||||||
}
|
}
|
||||||
//! Get the maximum out of two values
|
|
||||||
template<typename T> const T& max(const T& t1, const T& t2) {
|
|
||||||
return t2<t1?t1:t2;
|
|
||||||
}
|
|
||||||
//! Get the maximum out of three values
|
//! Get the maximum out of three values
|
||||||
template<typename T> const T& max(const T& t1, const T& t2, const T& t3) {
|
template<typename T> const T& max(const T& t1, const T& t2, const T& t3) {
|
||||||
return max(t1, max(t2, t3));
|
return max(t1, max(t2, t3));
|
||||||
@@ -91,6 +93,17 @@ namespace mrw {
|
|||||||
const T& t4, const T& t5, const T& t6) {
|
const T& t4, const T& t5, const T& t6) {
|
||||||
return max(max(t1, t2, t3), max(t4, t5, t6));
|
return max(max(t1, t2, t3), max(t4, t5, t6));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
//! Get the maximum out of any number of arguments
|
||||||
|
template<typename T, typename... T2> T& max(T& t1, T& t2, T2&... args) {
|
||||||
|
return max(t1, max(t2, args...));
|
||||||
|
}
|
||||||
|
//! Get the maximum out of any number of arguments
|
||||||
|
template<typename T, typename... T2> const T& max(const T& t1, const T& t2,
|
||||||
|
const T2&... args) {
|
||||||
|
return max(t1, max(t2, args...));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
/** @defgroup getmin Get the Minimum of Values */
|
/** @defgroup getmin Get the Minimum of Values */
|
||||||
@@ -99,6 +112,11 @@ namespace mrw {
|
|||||||
template<typename T> T& min(T& t1, T& t2) {
|
template<typename T> T& min(T& t1, T& t2) {
|
||||||
return t1<t2?t1:t2;
|
return t1<t2?t1:t2;
|
||||||
}
|
}
|
||||||
|
//! Get the minimum out of two values
|
||||||
|
template<typename T> const T& min(const T& t1, const T& t2) {
|
||||||
|
return t1<t2?t1:t2;
|
||||||
|
}
|
||||||
|
#ifdef MRW__OLD_PRE11_COMPILER
|
||||||
//! Get the minimum out of three values
|
//! Get the minimum out of three values
|
||||||
template<typename T> T& min(T& t1, T& t2, T& t3) {
|
template<typename T> T& min(T& t1, T& t2, T& t3) {
|
||||||
return min(t1, min(t2, t3));
|
return min(t1, min(t2, t3));
|
||||||
@@ -115,10 +133,6 @@ namespace mrw {
|
|||||||
template<typename T> T& min(T& t1, T& t2, T& t3, T& t4, T& t5, T& t6) {
|
template<typename T> T& min(T& t1, T& t2, T& t3, T& t4, T& t5, T& t6) {
|
||||||
return min(min(t1, t2, t3), min(t4, t5, t6));
|
return min(min(t1, t2, t3), min(t4, t5, t6));
|
||||||
}
|
}
|
||||||
//! Get the minimum out of two values
|
|
||||||
template<typename T> const T& min(const T& t1, const T& t2) {
|
|
||||||
return t2<t1?t1:t2;
|
|
||||||
}
|
|
||||||
//! Get the minimum out of three values
|
//! Get the minimum out of three values
|
||||||
template<typename T> const T& min(const T& t1, const T& t2, const T& t3) {
|
template<typename T> const T& min(const T& t1, const T& t2, const T& t3) {
|
||||||
return min(t1, min(t2, t3));
|
return min(t1, min(t2, t3));
|
||||||
@@ -138,6 +152,17 @@ namespace mrw {
|
|||||||
const T& t4, const T& t5, const T& t6) {
|
const T& t4, const T& t5, const T& t6) {
|
||||||
return min(min(t1, t2, t3), min(t4, t5, t6));
|
return min(min(t1, t2, t3), min(t4, t5, t6));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
//! Get the minimum out of any number of arguments
|
||||||
|
template<typename T, typename... T2> T& min(T& t1, T& t2, T2&... args) {
|
||||||
|
return min(t1, min(t2, args...));
|
||||||
|
}
|
||||||
|
//! Get the minimum out of any number of arguments
|
||||||
|
template<typename T, typename... T2> const T& min(const T& t1, const T& t2,
|
||||||
|
const T2&... args) {
|
||||||
|
return min(t1, min(t2, args...));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
/** @brief Dual <code>?:</code> operation:
|
/** @brief Dual <code>?:</code> operation:
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include <mrw/multiset.hxx>
|
#include <mrw/multiset.hxx>
|
||||||
#include <mrw/multimap.hxx>
|
#include <mrw/multimap.hxx>
|
||||||
#include <mrw/stacktrace.hxx>
|
#include <mrw/stacktrace.hxx>
|
||||||
|
#include <mrw/stdext.hxx>
|
||||||
#include <cppunit/TestFixture.h>
|
#include <cppunit/TestFixture.h>
|
||||||
#include <cppunit/ui/text/TestRunner.h>
|
#include <cppunit/ui/text/TestRunner.h>
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
@@ -37,233 +38,255 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
class StdExtTest: public CppUnit::TestFixture {
|
class StdExtTest: public CppUnit::TestFixture {
|
||||||
public:
|
public:
|
||||||
void StringConv() {
|
void StringConv() {
|
||||||
std::string s("Integer=");
|
std::string s("Integer=");
|
||||||
int i(-7382);
|
int i(-7382);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Integer=-7382"), s+mrw::string(i));
|
CPPUNIT_ASSERT_EQUAL(std::string("Integer=-7382"), s+mrw::string(i));
|
||||||
CPPUNIT_ASSERT_EQUAL(i, mrw::to<int>(mrw::string(i)));
|
CPPUNIT_ASSERT_EQUAL(i, mrw::to<int>(mrw::string(i)));
|
||||||
}
|
}
|
||||||
void StringShift() {
|
void StringShift() {
|
||||||
std::string s("Integer=");
|
std::string s("Integer=");
|
||||||
int i(4);
|
int i(4);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Integer=4 test 45 xx"),
|
CPPUNIT_ASSERT_EQUAL(std::string("Integer=4 test 45 xx"),
|
||||||
(s<<i<<" test "<<4<<(long)5<<" xx"));
|
(s<<i<<" test "<<4<<(long)5<<" xx"));
|
||||||
int i2 = 0;
|
int i2 = 0;
|
||||||
std::string s2, s3;
|
std::string s2, s3;
|
||||||
CPPUNIT_ASSERT_NO_THROW(s>>s2>>s3>>i2);
|
CPPUNIT_ASSERT_NO_THROW(s>>s2>>s3>>i2);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Integer=4"), s2);
|
CPPUNIT_ASSERT_EQUAL(std::string("Integer=4"), s2);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("test"), s3);
|
CPPUNIT_ASSERT_EQUAL(std::string("test"), s3);
|
||||||
CPPUNIT_ASSERT_EQUAL(45, i2);
|
CPPUNIT_ASSERT_EQUAL(45, i2);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(" xx"), s);
|
CPPUNIT_ASSERT_EQUAL(std::string(" xx"), s);
|
||||||
s2=""; s3="";
|
s2=""; s3="";
|
||||||
s>>s2;
|
s>>s2;
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("xx"), s2);
|
CPPUNIT_ASSERT_EQUAL(std::string("xx"), s2);
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(), s);
|
CPPUNIT_ASSERT_EQUAL(std::string(), s);
|
||||||
}
|
|
||||||
void StringAdd() {
|
|
||||||
std::string s;
|
|
||||||
s=s+(signed short)1+(signed int)2+(signed long)3+(signed char)'A'+
|
|
||||||
(unsigned short)1+(unsigned int)2+(unsigned long)3+(unsigned char)'A'+'c';
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("1236512365c"), s);
|
|
||||||
s=(signed short)-4+s;
|
|
||||||
s=(signed int)5+s;
|
|
||||||
s=(signed long)6+s;
|
|
||||||
s=(signed char)8+s;
|
|
||||||
s=(unsigned short)4+s;
|
|
||||||
s=(unsigned int)5+s;
|
|
||||||
s=(unsigned long)6+s;
|
|
||||||
s=(unsigned char)8+s;
|
|
||||||
s='a'+s;
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c"), s);
|
|
||||||
s+=(signed short)-4;
|
|
||||||
s+=(signed int)5 ;
|
|
||||||
s+=(signed long)6;
|
|
||||||
s+=(signed char)8 ;
|
|
||||||
s+=(unsigned short)4;
|
|
||||||
s+=(unsigned int)5 ;
|
|
||||||
s+=(unsigned long)6;
|
|
||||||
s+=(unsigned char)8 ;
|
|
||||||
s+='a';
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c-45684568a"), s);
|
|
||||||
}
|
|
||||||
void ListShift() {
|
|
||||||
std::list<int> l;
|
|
||||||
l<<1<<2<<3<<4<<5<<6<<7<<8;
|
|
||||||
int i1(0), i2(0), i3(0), i4(0);
|
|
||||||
l>>i1>>i2>>i3>>i4;
|
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
|
||||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::list<int>::size_type(4), l.size());
|
|
||||||
for (int i=0; i<4; (l.pop_front(), ++i)) {
|
|
||||||
CPPUNIT_ASSERT_EQUAL(i+5, l.front());
|
|
||||||
}
|
}
|
||||||
bool exc(false);
|
void StringAdd() {
|
||||||
try {
|
std::string s;
|
||||||
l>>i1;
|
s=s+(signed short)1+(signed int)2+(signed long)3+(signed char)'A'+
|
||||||
} catch (mrw::length_error&) {
|
(unsigned short)1+(unsigned int)2+(unsigned long)3+(unsigned char)'A'
|
||||||
exc=true;
|
+'c';
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("1236512365c"), s);
|
||||||
|
s=(signed short)-4+s;
|
||||||
|
s=(signed int)5+s;
|
||||||
|
s=(signed long)6+s;
|
||||||
|
s=(signed char)8+s;
|
||||||
|
s=(unsigned short)4+s;
|
||||||
|
s=(unsigned int)5+s;
|
||||||
|
s=(unsigned long)6+s;
|
||||||
|
s=(unsigned char)8+s;
|
||||||
|
s='a'+s;
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c"), s);
|
||||||
|
s+=(signed short)-4;
|
||||||
|
s+=(signed int)5 ;
|
||||||
|
s+=(signed long)6;
|
||||||
|
s+=(signed char)8 ;
|
||||||
|
s+=(unsigned short)4;
|
||||||
|
s+=(unsigned int)5 ;
|
||||||
|
s+=(unsigned long)6;
|
||||||
|
s+=(unsigned char)8 ;
|
||||||
|
s+='a';
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("a8654865-41236512365c-45684568a"), s);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void ListShift() {
|
||||||
}
|
std::list<int> l;
|
||||||
void VectorShift() {
|
l<<1<<2<<3<<4<<5<<6<<7<<8;
|
||||||
std::vector<int> l;
|
int i1(0), i2(0), i3(0), i4(0);
|
||||||
CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8);
|
l>>i1>>i2>>i3>>i4;
|
||||||
CPPUNIT_ASSERT_EQUAL(std::vector<int>::size_type(8), l.size());
|
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||||
int i1(0), i2(0), i3(0), i4(0);
|
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||||
CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4);
|
CPPUNIT_ASSERT_EQUAL(std::list<int>::size_type(4), l.size());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::vector<int>::size_type(4), l.size());
|
for (int i=0; i<4; (l.pop_front(), ++i)) {
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
CPPUNIT_ASSERT_EQUAL(i+5, l.front());
|
||||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
}
|
||||||
CPPUNIT_ASSERT(l.size()==4);
|
bool exc(false);
|
||||||
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
try {
|
||||||
CPPUNIT_ASSERT(l.front()==i+5);
|
l>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
bool exc(false);
|
void VectorShift() {
|
||||||
try {
|
std::vector<int> l;
|
||||||
l>>i1;
|
CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8);
|
||||||
} catch (mrw::length_error&) {
|
CPPUNIT_ASSERT_EQUAL(std::vector<int>::size_type(8), l.size());
|
||||||
exc=true;
|
int i1(0), i2(0), i3(0), i4(0);
|
||||||
|
CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::vector<int>::size_type(4), l.size());
|
||||||
|
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||||
|
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||||
|
CPPUNIT_ASSERT(l.size()==4);
|
||||||
|
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
||||||
|
CPPUNIT_ASSERT(l.front()==i+5);
|
||||||
|
}
|
||||||
|
bool exc(false);
|
||||||
|
try {
|
||||||
|
l>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void DequeShift() {
|
||||||
}
|
std::deque<int> l;
|
||||||
void DequeShift() {
|
CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8);
|
||||||
std::deque<int> l;
|
int i1(0), i2(0), i3(0), i4(0);
|
||||||
CPPUNIT_ASSERT_NO_THROW(l<<1<<2<<3<<4<<5<<6<<7<<8);
|
CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4);
|
||||||
int i1(0), i2(0), i3(0), i4(0);
|
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||||
CPPUNIT_ASSERT_NO_THROW(l>>i1>>i2>>i3>>i4);
|
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
CPPUNIT_ASSERT_EQUAL(std::deque<int>::size_type(4), l.size());
|
||||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
||||||
CPPUNIT_ASSERT_EQUAL(std::deque<int>::size_type(4), l.size());
|
CPPUNIT_ASSERT_EQUAL(i+5, l.front());
|
||||||
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
}
|
||||||
CPPUNIT_ASSERT_EQUAL(i+5, l.front());
|
bool exc(false);
|
||||||
|
try {
|
||||||
|
l>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
bool exc(false);
|
void SetShift() {
|
||||||
try {
|
std::set<int> s;
|
||||||
l>>i1;
|
bool exc(false);
|
||||||
} catch (mrw::length_error&) {
|
try {
|
||||||
exc=true;
|
s<<1<<2<<3<<4<<5<<6<<7<<8<<8;
|
||||||
|
} catch (mrw::invalid_argument& e) {
|
||||||
|
mrw::StackTrace::createSymtable();
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
|
int i1(0), i2(0), i3(0), i4(0);
|
||||||
|
s>>i1>>i2>>i3>>i4;
|
||||||
|
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||||
|
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::set<int>::size_type(4), s.size());
|
||||||
|
for (int i=0; i<4; ++i) {
|
||||||
|
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
||||||
|
}
|
||||||
|
s.erase(s.begin(), s.end());
|
||||||
|
exc=false;
|
||||||
|
try {
|
||||||
|
s>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void MapShift() {
|
||||||
}
|
typedef std::map<int, std::string> Map;
|
||||||
void SetShift() {
|
Map s;
|
||||||
std::set<int> s;
|
bool exc(false);
|
||||||
bool exc(false);
|
try {
|
||||||
try {
|
s<<std::make_pair(1, std::string("one"))
|
||||||
s<<1<<2<<3<<4<<5<<6<<7<<8<<8;
|
<<std::make_pair(2, std::string("two"))
|
||||||
} catch (mrw::invalid_argument& e) {
|
<<std::make_pair(2, std::string("two"));
|
||||||
mrw::StackTrace::createSymtable();
|
} catch (mrw::invalid_argument& e) {
|
||||||
exc=true;
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
|
std::pair<int, std::string> i1, i2;
|
||||||
|
s>>i1>>i2;
|
||||||
|
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||||
|
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
||||||
|
i2==std::make_pair(2, std::string("two")));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(Map::size_type(0), s.size());
|
||||||
|
exc=false;
|
||||||
|
try {
|
||||||
|
s>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void MultisetShift() {
|
||||||
int i1(0), i2(0), i3(0), i4(0);
|
std::multiset<int> s;
|
||||||
s>>i1>>i2>>i3>>i4;
|
s<<1<<2<<3<<4<<5<<6<<7<<8<<9;
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
int i1(0), i2(0), i3(0), i4(0);
|
||||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
s>>i1>>i2>>i3>>i4;
|
||||||
CPPUNIT_ASSERT_EQUAL(std::set<int>::size_type(4), s.size());
|
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||||
for (int i=0; i<4; ++i) {
|
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||||
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
CPPUNIT_ASSERT_EQUAL(std::multiset<int>::size_type(5), s.size());
|
||||||
|
for (int i=0; i<5; ++i) {
|
||||||
|
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
||||||
|
}
|
||||||
|
s.erase(s.begin(), s.end());
|
||||||
|
bool exc(false);
|
||||||
|
try {
|
||||||
|
s>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
s.erase(s.begin(), s.end());
|
void MultimapShift() {
|
||||||
exc=false;
|
typedef std::multimap<int, std::string> Map;
|
||||||
try {
|
Map s;
|
||||||
s>>i1;
|
|
||||||
} catch (mrw::length_error&) {
|
|
||||||
exc=true;
|
|
||||||
}
|
|
||||||
CPPUNIT_ASSERT(exc);
|
|
||||||
}
|
|
||||||
void MapShift() {
|
|
||||||
typedef std::map<int, std::string> Map;
|
|
||||||
Map s;
|
|
||||||
bool exc(false);
|
|
||||||
try {
|
|
||||||
s<<std::make_pair(1, std::string("one"))
|
s<<std::make_pair(1, std::string("one"))
|
||||||
<<std::make_pair(2, std::string("two"))
|
<<std::make_pair(2, std::string("two"))
|
||||||
<<std::make_pair(2, std::string("two"));
|
<<std::make_pair(2, std::string("two"));
|
||||||
} catch (mrw::invalid_argument& e) {
|
std::pair<int, std::string> i1, i2;
|
||||||
exc=true;
|
s>>i1>>i2;
|
||||||
}
|
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||||
CPPUNIT_ASSERT(exc);
|
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
||||||
std::pair<int, std::string> i1, i2;
|
i2==std::make_pair(2, std::string("two")));
|
||||||
s>>i1>>i2;
|
CPPUNIT_ASSERT_EQUAL(Map::size_type(1), s.size());
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
|
||||||
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
|
||||||
i2==std::make_pair(2, std::string("two")));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(Map::size_type(0), s.size());
|
|
||||||
exc=false;
|
|
||||||
try {
|
|
||||||
s>>i1;
|
s>>i1;
|
||||||
} catch (mrw::length_error&) {
|
CPPUNIT_ASSERT(std::make_pair(2, std::string("two"))==i1);
|
||||||
exc=true;
|
bool exc(false);
|
||||||
|
try {
|
||||||
|
s>>i1;
|
||||||
|
} catch (mrw::length_error&) {
|
||||||
|
exc=true;
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT(exc);
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void StringException1() {
|
||||||
}
|
std::string s("Hello World");
|
||||||
void MultisetShift() {
|
int hello;
|
||||||
std::multiset<int> s;
|
s>>hello; // not an int, exception expected
|
||||||
s<<1<<2<<3<<4<<5<<6<<7<<8<<9;
|
|
||||||
int i1(0), i2(0), i3(0), i4(0);
|
|
||||||
s>>i1>>i2>>i3>>i4;
|
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
|
||||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::multiset<int>::size_type(5), s.size());
|
|
||||||
for (int i=0; i<5; ++i) {
|
|
||||||
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
|
||||||
}
|
}
|
||||||
s.erase(s.begin(), s.end());
|
void StringException2() {
|
||||||
bool exc(false);
|
std::string s("Hello World");
|
||||||
try {
|
mrw::to<int>(s); // not an int, exception expected
|
||||||
s>>i1;
|
|
||||||
} catch (mrw::length_error&) {
|
|
||||||
exc=true;
|
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void Max() {
|
||||||
}
|
int a1(3), a2(23), a3(2), a4(432), a5(73), a6(32);
|
||||||
void MultimapShift() {
|
CPPUNIT_ASSERT_EQUAL(432, mrw::max(a1, a2, a3, a4, a5, a6));
|
||||||
typedef std::multimap<int, std::string> Map;
|
CPPUNIT_ASSERT_EQUAL(432, mrw::max(a1, a2, a3, a4, a5, a6));
|
||||||
Map s;
|
CPPUNIT_ASSERT_EQUAL(73, mrw::max(a1, a2, a3, a5, a6));
|
||||||
s<<std::make_pair(1, std::string("one"))
|
CPPUNIT_ASSERT_EQUAL(32, mrw::max(a1, a2, a3, a6));
|
||||||
<<std::make_pair(2, std::string("two"))
|
CPPUNIT_ASSERT_EQUAL(23, mrw::max(a1, a2, a3));
|
||||||
<<std::make_pair(2, std::string("two"));
|
CPPUNIT_ASSERT_EQUAL(3, mrw::max(a1, a3));
|
||||||
std::pair<int, std::string> i1, i2;
|
CPPUNIT_ASSERT_EQUAL(42, mrw::max(3, 42, 6, 1));
|
||||||
s>>i1>>i2;
|
|
||||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
|
||||||
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
|
||||||
i2==std::make_pair(2, std::string("two")));
|
|
||||||
CPPUNIT_ASSERT_EQUAL(Map::size_type(1), s.size());
|
|
||||||
s>>i1;
|
|
||||||
CPPUNIT_ASSERT(std::make_pair(2, std::string("two"))==i1);
|
|
||||||
bool exc(false);
|
|
||||||
try {
|
|
||||||
s>>i1;
|
|
||||||
} catch (mrw::length_error&) {
|
|
||||||
exc=true;
|
|
||||||
}
|
}
|
||||||
CPPUNIT_ASSERT(exc);
|
void Min() {
|
||||||
}
|
int a1(3), a2(23), a3(2), a4(432), a5(73), a6(32);
|
||||||
void StringException1() {
|
CPPUNIT_ASSERT_EQUAL(2, mrw::min(a1, a2, a3, a4, a5, a6));
|
||||||
std::string s("Hello World");
|
CPPUNIT_ASSERT_EQUAL(3, mrw::min(a1, a2, a4, a5, a6));
|
||||||
int hello;
|
CPPUNIT_ASSERT_EQUAL(23, mrw::min(a2, a4, a5, a6));
|
||||||
s>>hello; // not an int, exception expected
|
CPPUNIT_ASSERT_EQUAL(32, mrw::min(a4, a5, a6));
|
||||||
}
|
CPPUNIT_ASSERT_EQUAL(73, mrw::min(a4, a5));
|
||||||
void StringException2() {
|
CPPUNIT_ASSERT_EQUAL(42, mrw::min(323, 42, 126, 91));
|
||||||
std::string s("Hello World");
|
}
|
||||||
mrw::to<int>(s); // not an int, exception expected
|
CPPUNIT_TEST_SUITE(StdExtTest);
|
||||||
}
|
CPPUNIT_TEST(StringConv);
|
||||||
CPPUNIT_TEST_SUITE(StdExtTest);
|
CPPUNIT_TEST(StringShift);
|
||||||
CPPUNIT_TEST(StringConv);
|
CPPUNIT_TEST(StringAdd);
|
||||||
CPPUNIT_TEST(StringShift);
|
CPPUNIT_TEST(ListShift);
|
||||||
CPPUNIT_TEST(StringAdd);
|
CPPUNIT_TEST(VectorShift);
|
||||||
CPPUNIT_TEST(ListShift);
|
CPPUNIT_TEST(DequeShift);
|
||||||
CPPUNIT_TEST(VectorShift);
|
CPPUNIT_TEST(SetShift);
|
||||||
CPPUNIT_TEST(DequeShift);
|
CPPUNIT_TEST(MapShift);
|
||||||
CPPUNIT_TEST(SetShift);
|
CPPUNIT_TEST(MultisetShift);
|
||||||
CPPUNIT_TEST(MapShift);
|
CPPUNIT_TEST(MultimapShift);
|
||||||
CPPUNIT_TEST(MultisetShift);
|
CPPUNIT_TEST(Max);
|
||||||
CPPUNIT_TEST(MultimapShift);
|
CPPUNIT_TEST(Min);
|
||||||
CPPUNIT_TEST_EXCEPTION(StringException1, mrw::invalid_argument);
|
CPPUNIT_TEST_EXCEPTION(StringException1, mrw::invalid_argument);
|
||||||
CPPUNIT_TEST_EXCEPTION(StringException2, mrw::invalid_argument);
|
CPPUNIT_TEST_EXCEPTION(StringException2, mrw::invalid_argument);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
};
|
};
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(StdExtTest);
|
CPPUNIT_TEST_SUITE_REGISTRATION(StdExtTest);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user