#include <string>
#include <stdexcept>
#include <testsuite_hooks.h>
bool test01(void)
{
bool test = true;
typedef std::string::size_type csize_type;
typedef std::string::const_reference cref;
typedef std::string::reference ref;
csize_type npos = std::string::npos;
csize_type csz01, csz02;
const std::string str01("tamarindo, costa rica");
std::string str02("41st street beach, capitola, california");
std::string str03;
csz01 = str01.size();
cref cref1 = str01[csz01 - 1];
VERIFY( cref1 == 'a' );
cref cref2 = str01[csz01];
VERIFY( cref2 == char() );
csz02 = str02.size();
ref ref1 = str02[csz02 - 1];
VERIFY( ref1 == 'a' );
ref ref2 = str02[1];
VERIFY( ref2 == '1' );
csz01 = str01.size();
cref cref3 = str01.at(csz01 - 1);
VERIFY( cref3 == 'a' );
try {
cref cref4 = str01.at(csz01);
VERIFY( false ); }
catch(std::out_of_range& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
csz01 = str02.size();
ref ref3 = str02.at(csz02 - 1);
VERIFY( ref3 == 'a' );
try {
ref ref4 = str02.at(csz02);
VERIFY( false ); }
catch(std::out_of_range& fail) {
VERIFY( true );
}
catch(...) {
VERIFY( false );
}
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
}
int main()
{
test01();
return 0;
}