rewritten manualtest.cpp to be nicer and more readable
This commit is contained in:
parent
b9485acce8
commit
8ef6635b9d
129
manualtest.cpp
129
manualtest.cpp
@ -1,30 +1,121 @@
|
||||
#include<iostream>
|
||||
#include<sstream>
|
||||
#include<cstring>
|
||||
#include <type_traits>
|
||||
#include"String.h"
|
||||
|
||||
|
||||
|
||||
/* This is a demonstration, that the String class and it's components work
|
||||
* correctly, basically a non-unit test. */
|
||||
int main()
|
||||
{
|
||||
String str1;
|
||||
if (std::is_default_constructible<String>::value)
|
||||
std::cout << "class String is default constructible" << std::endl;
|
||||
if (std::is_constructible<String, const char*>::value)
|
||||
std::cout << "class String is constructible from const char*" << std::endl;
|
||||
if (std::is_copy_constructible<String>::value)
|
||||
std::cout << "class String is copy constructible" << std::endl;
|
||||
if (std::is_copy_assignable<String>::value)
|
||||
std::cout << "class String is copy assignable" << std::endl;
|
||||
if (std::is_move_constructible<String>::value)
|
||||
std::cout << "class String is move constructible" << std::endl;
|
||||
if (std::is_move_assignable<String>::value)
|
||||
std::cout << "class String is move assignable" << std::endl;
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
String str("cica");
|
||||
if (!std::strcmp(str.c_str(), "cica"))
|
||||
std::cout << "String::c_str() method works" << std::endl;
|
||||
|
||||
String uninitialized;
|
||||
try { uninitialized.c_str(); }
|
||||
catch (std::runtime_error)
|
||||
{ std::cout << "String::c_str() throws if String is not initialized" << std::endl; }
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
String sajt("sajt");
|
||||
if (!std::strcmp((str+sajt).c_str(), "cicasajt"))
|
||||
std::cout << "String::operator+ works with other Strings" << std::endl;
|
||||
|
||||
String cica(str);
|
||||
cica += sajt;
|
||||
if (!std::strcmp(cica.c_str(), "cicasajt"))
|
||||
std::cout << "String::operator+= works with other Strings" << std::endl;
|
||||
|
||||
String cica1("cicá");
|
||||
if (!std::strcmp((cica1+'k').c_str(), "cicák"))
|
||||
std::cout << "String::operator+ works with char primitives" << std::endl;
|
||||
|
||||
cica1 += 'k';
|
||||
if (!std::strcmp(cica1.c_str(), "cicák"))
|
||||
std::cout << "String::operator+= works with char primitives" << std::endl;
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
String sajt1(sajt);
|
||||
if (sajt == sajt1)
|
||||
std::cout << "String::operator== works" << std::endl;
|
||||
|
||||
try { uninitialized == sajt; }
|
||||
catch (std::runtime_error)
|
||||
{ std::cout << "String::operator== throws if String is not initialized" << std::endl; }
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
if (str[1] == 'i')
|
||||
std::cout << "String::operator[] works" << std::endl;
|
||||
|
||||
try { str[8]; }
|
||||
catch (std::out_of_range)
|
||||
{ std::cout << "String::operator[] throws when index is out of range" << std::endl; }
|
||||
|
||||
try { uninitialized[0]; }
|
||||
catch (std::runtime_error)
|
||||
{ std::cout << "String::operator[] throws when String is not initialized" << std::endl; }
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
String tej("tej");
|
||||
String tej1 = tej;
|
||||
tej1[0] = 's';
|
||||
if (!std::strcmp(tej.c_str(), "tej") && !std::strcmp(tej1.c_str(), "sej"))
|
||||
std::cout << "Copy-on-write works when indexing Strings" << std::endl;
|
||||
|
||||
String lel("lel");
|
||||
String lel1("lel");
|
||||
|
||||
if (lel.c_str() == lel1.c_str())
|
||||
std::cout << "Resource sharing works on Strings" << std::endl;
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
std::stringstream stream;
|
||||
stream << "sajt";
|
||||
stream >> str1;
|
||||
std::cout << str1 << std::endl;
|
||||
String str2(" cicasajt");
|
||||
String str3(str2);
|
||||
str2 = str1;
|
||||
String str4(String("sajtos cica"));
|
||||
str2 = String(" tihihi");
|
||||
std::cout << str4 + str3 << std::endl;
|
||||
std::cout << ((str4 + str3)+=str2) << std::endl;
|
||||
str4 += 'k';
|
||||
std::cout << str4 << std::endl;
|
||||
std::cout << str2+'k' << std::endl;
|
||||
std::cout << str4[0] << static_cast<const String>(str2)[1] << std::endl;
|
||||
String str5 = str2;
|
||||
str5[0] = 'i';
|
||||
std::cout << str5 << std::endl;
|
||||
std::cout << str2 << std::endl;
|
||||
stream << lel;
|
||||
if (!std::strcmp(stream.str().c_str(), lel.c_str()))
|
||||
std::cout << "ostream operator<< works on Strings" << std::endl;
|
||||
|
||||
stream = std::stringstream();
|
||||
|
||||
stream << "C++11";
|
||||
stream >> uninitialized;
|
||||
if (!std::strcmp(uninitialized.c_str(), "C++11"))
|
||||
std::cout << "istream operator>> works on Strings" << std::endl;
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user