generated from CSCI200/Template
finish
This commit is contained in:
parent
7617dffd08
commit
5be7b56660
10 changed files with 601 additions and 352 deletions
BIN
L3B
BIN
L3B
Binary file not shown.
|
@ -1,3 +1,5 @@
|
||||||
|
All personal code of mine is licensed under the following CC0 license, however most of the code (all of main.cpp, all of test_suite.cpp, and all but the actual string logic in string_functions.cpp) was written by Jeffrey R. Paone and is licensed under the MIT license
|
||||||
|
|
||||||
# Creative Commons CC0 1.0 Universal
|
# Creative Commons CC0 1.0 Universal
|
||||||
|
|
||||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
|
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -1,15 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* @file main.cpp
|
* @file main.cpp
|
||||||
* @author Tyler Beckman (tyler_beckman@mines.edu)
|
* @author Tyler Beckman (tyler_beckman@mines.edu)
|
||||||
* @brief CSCI200 L3B - A program to test different string modification APIs in C++
|
* @brief CSCI200 L3B - A program to test different string modification APIs in
|
||||||
|
* C++
|
||||||
* @version 1
|
* @version 1
|
||||||
* @date 2024-09-21
|
* @date 2024-09-21
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "test_suite.h"
|
#include "test_suite.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
std::cout << "Testing your functions..." << std::endl << std::endl;
|
std::cout << "Testing your functions..." << std::endl << std::endl;
|
||||||
|
|
BIN
main.o
BIN
main.o
Binary file not shown.
|
@ -13,94 +13,103 @@ unsigned long string_length(const string STR) {
|
||||||
char string_char_at(const string STR, const int IDX) {
|
char string_char_at(const string STR, const int IDX) {
|
||||||
char result = '\0';
|
char result = '\0';
|
||||||
result = STR.at(IDX);
|
result = STR.at(IDX);
|
||||||
std::cout << "TODO: implement string_char_at(\"" << STR << "\", " << IDX << ")" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_append(const string LEFT, const string RIGHT) {
|
string string_append(const string LEFT, const string RIGHT) {
|
||||||
string result = LEFT;
|
string result = LEFT;
|
||||||
result = LEFT + RIGHT;
|
result = LEFT + RIGHT;
|
||||||
std::cout << "TODO: implement string_append(\"" << LEFT << "\", \"" << RIGHT << "\")" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_insert(const string STR, const string TO_INSERT, const int IDX) {
|
string string_insert(const string STR, const string TO_INSERT, const int IDX) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
result.insert(IDX, TO_INSERT);
|
result.insert(IDX, TO_INSERT);
|
||||||
std::cout << "TODO: implement string_insert(\"" << STR << "\", \"" << TO_INSERT << "\", " << IDX << ")" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t string_find(const string STR, const char C) {
|
size_t string_find(const string STR, const char C) {
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
result = STR.find_first_of(C);
|
result = STR.find_first_of(C);
|
||||||
std::cout << "TODO: implement string_find(\"" << STR << "\", '" << C << "')" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_substring(const string STR, const int IDX, const int LEN) {
|
string string_substring(const string STR, const int IDX, const int LEN) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
result = STR.substr(IDX, LEN);
|
result = STR.substr(IDX, LEN);
|
||||||
std::cout << "TODO: implement string_substring(\"" << STR << "\", " << IDX << ", " << LEN << ")" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_replace(const string STR, const string TEXT_TO_REPLACE, const string REPLACE_WITH) {
|
string string_replace(const string STR, const string TEXT_TO_REPLACE,
|
||||||
|
const string REPLACE_WITH) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
auto index = STR.find(TEXT_TO_REPLACE);
|
auto index = STR.find(TEXT_TO_REPLACE);
|
||||||
if (index != -1ul) {
|
if (index != -1ul) {
|
||||||
result.replace(STR.find(TEXT_TO_REPLACE), TEXT_TO_REPLACE.length(), REPLACE_WITH);
|
result.replace(STR.find(TEXT_TO_REPLACE), TEXT_TO_REPLACE.length(),
|
||||||
|
REPLACE_WITH);
|
||||||
}
|
}
|
||||||
std::cout << "TODO: implement string_replace(\"" << STR << "\", \"" << TEXT_TO_REPLACE << "\", \"" << REPLACE_WITH << ")\"" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_first_word(const string STR) {
|
string string_first_word(const string STR) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
result = STR.substr(0, STR.find_first_of(' '));
|
result = STR.substr(0, STR.find_first_of(' '));
|
||||||
std::cout << "TODO: implement string_first_word(\"" << STR << "\")" << std::endl;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_remove_first_word(const string STR) {
|
string string_remove_first_word(const string STR) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
// TODO 08: set result to be the string with the first word removed
|
if (STR.find_first_of(' ') != -1ul) {
|
||||||
std::cout << "TODO: implement string_remove_first_word(\"" << STR << ")\"" << std::endl;
|
result = STR.substr(STR.find_first_of(' ') + 1, STR.length() - 1);
|
||||||
|
} else {
|
||||||
|
result = "";
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_second_word(const string STR) {
|
string string_second_word(const string STR) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
// TODO 09: set result to be the second word from the string
|
result = string_remove_first_word(STR);
|
||||||
std::cout << "TODO: implement string_second_word(\"" << STR << "\")" << std::endl;
|
result = string_first_word(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_third_word(const string STR) {
|
string string_third_word(const string STR) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
// TODO 10: set result to be the third word from the string
|
result = string_remove_first_word(STR);
|
||||||
std::cout << "TODO: implement string_third_word(\"" << STR << "\")" << std::endl;
|
result = string_remove_first_word(result);
|
||||||
|
result = string_first_word(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_nth_word(const string STR, const int N) {
|
string string_nth_word(const string STR, const int N) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
// TODO 11: set result to be the nth word from the string
|
for (int i = 0; i < N - 1; i++) {
|
||||||
std::cout << "TODO: implement string_nth_word(\"" << STR << "\", " << N << ")" << std::endl;
|
result = string_remove_first_word(result);
|
||||||
|
}
|
||||||
|
result = string_first_word(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> string_tokenize(const string STR, const char DELIMINATOR) {
|
vector<string> string_tokenize(const string STR, const char DELIMINATOR) {
|
||||||
vector<string> result;
|
vector<string> result;
|
||||||
// TODO 12: split the string by the given deliminator
|
result = {""};
|
||||||
std::cout << "TODO: implement string_tokenize(\"" << STR << "\", '" << DELIMINATOR << "')" << std::endl;
|
for (unsigned long i = 0; i < STR.length(); i++) {
|
||||||
|
if (STR[i] == DELIMINATOR) {
|
||||||
|
result.push_back("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result[result.size() - 1] += STR[i];
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string string_substitute(const string STR, const char TARGET, const char REPLACEMENT) {
|
string string_substitute(const string STR, const char TARGET,
|
||||||
|
const char REPLACEMENT) {
|
||||||
string result = STR;
|
string result = STR;
|
||||||
// TODO 13: set result to be the string with all instances of TARGET replaced
|
while (result.find(TARGET) != -1ul) {
|
||||||
std::cout << "TODO: implement string_substitute(\"" << STR << "\", '" << TARGET << "', '" << REPLACEMENT << "')" << std::endl;
|
result[result.find(TARGET)] = REPLACEMENT;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +122,8 @@ string string_to_lower(const string STR) {
|
||||||
}
|
}
|
||||||
result[i] = newChar;
|
result[i] = newChar;
|
||||||
}
|
}
|
||||||
std::cout << "TODO: implement string_to_lower(\"" << STR << "\")" << std::endl;
|
std::cout << "TODO: implement string_to_lower(\"" << STR << "\")"
|
||||||
|
<< std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +136,8 @@ string string_to_upper(const string STR) {
|
||||||
}
|
}
|
||||||
result[i] = newChar;
|
result[i] = newChar;
|
||||||
}
|
}
|
||||||
std::cout << "TODO: implement string_to_upper(\"" << STR << "\")" << std::endl;
|
std::cout << "TODO: implement string_to_upper(\"" << STR << "\")"
|
||||||
|
<< std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +150,7 @@ int string_compare(const string LHS, const string RHS) {
|
||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "TODO: implement string_compare(\"" << LHS << "\", \"" << RHS << "\")" << std::endl;
|
std::cout << "TODO: implement string_compare(\"" << LHS << "\", \"" << RHS
|
||||||
|
<< "\")" << std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
|
@ -28,19 +28,22 @@ char string_char_at(const std::string STR, const int IDX);
|
||||||
std::string string_append(const std::string LEFT, const std::string RIGHT);
|
std::string string_append(const std::string LEFT, const std::string RIGHT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the result of inserting a string into another at a given position
|
* @brief Returns the result of inserting a string into another at a given
|
||||||
|
* position
|
||||||
* @param STR original string
|
* @param STR original string
|
||||||
* @param TO_INSERT string to be inserted into STR
|
* @param TO_INSERT string to be inserted into STR
|
||||||
* @param IDX location within STR to insert TO_INSERT
|
* @param IDX location within STR to insert TO_INSERT
|
||||||
* @return a new string with TO_INSERT inserted at index IDX of STR
|
* @return a new string with TO_INSERT inserted at index IDX of STR
|
||||||
*/
|
*/
|
||||||
std::string string_insert(const std::string STR, const std::string TO_INSERT, const int IDX);
|
std::string string_insert(const std::string STR, const std::string TO_INSERT,
|
||||||
|
const int IDX);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the first index of a character in a string
|
* @brief Returns the first index of a character in a string
|
||||||
* @param STR string to search within (the haystack)
|
* @param STR string to search within (the haystack)
|
||||||
* @param C character to search for (the needle)
|
* @param C character to search for (the needle)
|
||||||
* @return if found, first position within STR that C is located. otherwise returns string::npos
|
* @return if found, first position within STR that C is located. otherwise
|
||||||
|
* returns string::npos
|
||||||
*/
|
*/
|
||||||
size_t string_find(const std::string STR, const char C);
|
size_t string_find(const std::string STR, const char C);
|
||||||
|
|
||||||
|
@ -51,7 +54,8 @@ size_t string_find(const std::string STR, const char C);
|
||||||
* @param LEN length of substring to return
|
* @param LEN length of substring to return
|
||||||
* @return a substring of length LEN from STR
|
* @return a substring of length LEN from STR
|
||||||
*/
|
*/
|
||||||
std::string string_substring(const std::string STR, const int IDX, const int LEN);
|
std::string string_substring(const std::string STR, const int IDX,
|
||||||
|
const int LEN);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Replaces part of a string
|
* @brief Replaces part of a string
|
||||||
|
@ -60,7 +64,9 @@ std::string string_substring(const std::string STR, const int IDX, const int LEN
|
||||||
* @param REPLACE_WITH the new text to insert
|
* @param REPLACE_WITH the new text to insert
|
||||||
* @return modified string (if text found), otherwise the original string
|
* @return modified string (if text found), otherwise the original string
|
||||||
*/
|
*/
|
||||||
std::string string_replace(const std::string STR, const std::string TEXT_TO_REPLACE, const std::string REPLACE_WITH);
|
std::string string_replace(const std::string STR,
|
||||||
|
const std::string TEXT_TO_REPLACE,
|
||||||
|
const std::string REPLACE_WITH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the first word, given a sentence
|
* @brief Returns the first word, given a sentence
|
||||||
|
@ -103,21 +109,26 @@ std::string string_nth_word(const std::string STR, const int N);
|
||||||
*
|
*
|
||||||
* @param STR string to tokenize
|
* @param STR string to tokenize
|
||||||
* @param DELIMINATOR character to split on
|
* @param DELIMINATOR character to split on
|
||||||
* @return vector<string> list of all tokens in the order present in the original string
|
* @return vector<string> list of all tokens in the order present in the
|
||||||
|
* original string
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> string_tokenize(const std::string STR, const char DELIMINATOR);
|
std::vector<std::string> string_tokenize(const std::string STR,
|
||||||
|
const char DELIMINATOR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a string substituting target character with replacement character
|
* @brief Returns a string substituting target character with replacement
|
||||||
|
* character
|
||||||
* @param STR original full string (the haystack)
|
* @param STR original full string (the haystack)
|
||||||
* @param TARGET character to replace (the needle)
|
* @param TARGET character to replace (the needle)
|
||||||
* @param REPLACEMENT character to substitute with
|
* @param REPLACEMENT character to substitute with
|
||||||
* @return string with all instance of TARGET replaced with REPLACEMENT
|
* @return string with all instance of TARGET replaced with REPLACEMENT
|
||||||
*/
|
*/
|
||||||
std::string string_substitute(const std::string STR, const char TARGET, const char REPLACEMENT);
|
std::string string_substitute(const std::string STR, const char TARGET,
|
||||||
|
const char REPLACEMENT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a string with all uppercase characters converted to lowercase characters
|
* @brief Returns a string with all uppercase characters converted to lowercase
|
||||||
|
* characters
|
||||||
*
|
*
|
||||||
* @param STR original string
|
* @param STR original string
|
||||||
* @return string with lowercase characters
|
* @return string with lowercase characters
|
||||||
|
@ -125,7 +136,8 @@ std::string string_substitute(const std::string STR, const char TARGET, const ch
|
||||||
std::string string_to_lower(const std::string STR);
|
std::string string_to_lower(const std::string STR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a string with all lowercase characters converted to uppercase characters
|
* @brief Returns a string with all lowercase characters converted to uppercase
|
||||||
|
* characters
|
||||||
*
|
*
|
||||||
* @param STR original string
|
* @param STR original string
|
||||||
* @return string with uppercase characters
|
* @return string with uppercase characters
|
||||||
|
@ -133,8 +145,8 @@ std::string string_to_lower(const std::string STR);
|
||||||
std::string string_to_upper(const std::string STR);
|
std::string string_to_upper(const std::string STR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compares two strings to determine their ordering or equality. Returns -1 if
|
* @brief Compares two strings to determine their ordering or equality. Returns
|
||||||
* LHS < RHS. Returns 0 if LHS == RHS. Returns 1 if LHS > RHS
|
* -1 if LHS < RHS. Returns 0 if LHS == RHS. Returns 1 if LHS > RHS
|
||||||
*
|
*
|
||||||
* @param LHS left hand string
|
* @param LHS left hand string
|
||||||
* @param RHS right hand string
|
* @param RHS right hand string
|
||||||
|
|
Binary file not shown.
484
test_suite.cpp
484
test_suite.cpp
|
@ -1,4 +1,5 @@
|
||||||
#include "test_suite.h"
|
#include "test_suite.h"
|
||||||
|
|
||||||
#include "string_functions.h"
|
#include "string_functions.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -13,50 +14,62 @@ int test_int(int& testNum, const string MESSAGE, const int LHS, const int RHS)
|
||||||
cout << setw(MESSAGE_WIDTH) << right;
|
cout << setw(MESSAGE_WIDTH) << right;
|
||||||
cout << MESSAGE << ": ";
|
cout << MESSAGE << ": ";
|
||||||
cout << left;
|
cout << left;
|
||||||
if (LHS == RHS)
|
if (LHS == RHS) {
|
||||||
cout << " PASSED \n";
|
cout << " PASSED \n";
|
||||||
else
|
} else {
|
||||||
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS << "\"\n";
|
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS
|
||||||
|
<< "\"\n";
|
||||||
|
}
|
||||||
return LHS == RHS ? 1 : 0;
|
return LHS == RHS ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_size_t(int& testNum, const string MESSAGE, const size_t LHS, const size_t RHS) {
|
int test_size_t(int& testNum, const string MESSAGE, const size_t LHS,
|
||||||
|
const size_t RHS) {
|
||||||
cout << "Test #" << setw(3) << right << ++testNum;
|
cout << "Test #" << setw(3) << right << ++testNum;
|
||||||
cout << setw(MESSAGE_WIDTH) << right;
|
cout << setw(MESSAGE_WIDTH) << right;
|
||||||
cout << MESSAGE << ": ";
|
cout << MESSAGE << ": ";
|
||||||
cout << left;
|
cout << left;
|
||||||
if (LHS == RHS)
|
if (LHS == RHS) {
|
||||||
cout << " PASSED \n";
|
cout << " PASSED \n";
|
||||||
else
|
} else {
|
||||||
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS << "\"\n";
|
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS
|
||||||
|
<< "\"\n";
|
||||||
|
}
|
||||||
return LHS == RHS ? 1 : 0;
|
return LHS == RHS ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_char(int& testNum, const string MESSAGE, const char LHS, const char RHS) {
|
int test_char(int& testNum, const string MESSAGE, const char LHS,
|
||||||
|
const char RHS) {
|
||||||
cout << "Test #" << setw(3) << right << ++testNum;
|
cout << "Test #" << setw(3) << right << ++testNum;
|
||||||
cout << setw(MESSAGE_WIDTH) << right;
|
cout << setw(MESSAGE_WIDTH) << right;
|
||||||
cout << MESSAGE << ": ";
|
cout << MESSAGE << ": ";
|
||||||
cout << left;
|
cout << left;
|
||||||
if (LHS == RHS)
|
if (LHS == RHS) {
|
||||||
cout << " PASSED \n";
|
cout << " PASSED \n";
|
||||||
else
|
} else {
|
||||||
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS << "\"\n";
|
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS
|
||||||
|
<< "\"\n";
|
||||||
|
}
|
||||||
return LHS == RHS ? 1 : 0;
|
return LHS == RHS ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_string(int& testNum, const string MESSAGE, const string LHS, const string RHS) {
|
int test_string(int& testNum, const string MESSAGE, const string LHS,
|
||||||
|
const string RHS) {
|
||||||
cout << "Test #" << setw(3) << right << ++testNum;
|
cout << "Test #" << setw(3) << right << ++testNum;
|
||||||
cout << setw(MESSAGE_WIDTH) << right;
|
cout << setw(MESSAGE_WIDTH) << right;
|
||||||
cout << MESSAGE << ": ";
|
cout << MESSAGE << ": ";
|
||||||
cout << left;
|
cout << left;
|
||||||
if (LHS == RHS)
|
if (LHS == RHS) {
|
||||||
cout << " PASSED \n";
|
cout << " PASSED \n";
|
||||||
else
|
} else {
|
||||||
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS << "\"\n";
|
cout << " !!>FAILED<!! Returned: \"" << LHS << "\" != Expected: \"" << RHS
|
||||||
|
<< "\"\n";
|
||||||
|
}
|
||||||
return LHS == RHS ? 1 : 0;
|
return LHS == RHS ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_vector_string(int& testNum, const string MESSAGE, const vector<string>& LHS, const vector<string>& RHS) {
|
int test_vector_string(int& testNum, const string MESSAGE,
|
||||||
|
const vector<string>& LHS, const vector<string>& RHS) {
|
||||||
cout << "Test #" << setw(3) << right << ++testNum;
|
cout << "Test #" << setw(3) << right << ++testNum;
|
||||||
cout << setw(MESSAGE_WIDTH) << right;
|
cout << setw(MESSAGE_WIDTH) << right;
|
||||||
cout << MESSAGE << ": ";
|
cout << MESSAGE << ": ";
|
||||||
|
@ -95,162 +108,365 @@ int test_vector_string(int& testNum, const string MESSAGE, const vector<string>&
|
||||||
|
|
||||||
bool run_all_tests() {
|
bool run_all_tests() {
|
||||||
int totalPassed = 0, totalNumTests = 0;
|
int totalPassed = 0, totalNumTests = 0;
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_length()", string_length("Now") , 3 );
|
totalPassed += test_size_t(totalNumTests, "Testing string_length()",
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_length()", string_length("Tablet") , 6 );
|
string_length("Now"), 3);
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_length()", string_length("The length is 17.") , 17 );
|
totalPassed += test_size_t(totalNumTests, "Testing string_length()",
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_length()", string_length("A") , 1 );
|
string_length("Tablet"), 6);
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_length()", string_length("") , 0 );
|
totalPassed += test_size_t(totalNumTests, "Testing string_length()",
|
||||||
|
string_length("The length is 17."), 17);
|
||||||
|
totalPassed += test_size_t(totalNumTests, "Testing string_length()",
|
||||||
|
string_length("A"), 1);
|
||||||
|
totalPassed += test_size_t(totalNumTests, "Testing string_length()",
|
||||||
|
string_length(""), 0);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_char( totalNumTests, "Testing string_char_at()", string_char_at("Elephant", 3) , 'p' );
|
totalPassed += test_char(totalNumTests, "Testing string_char_at()",
|
||||||
totalPassed += test_char( totalNumTests, "Testing string_char_at()", string_char_at("Giraffe", 2) , 'r' );
|
string_char_at("Elephant", 3), 'p');
|
||||||
totalPassed += test_char( totalNumTests, "Testing string_char_at()", string_char_at("Armadillo", 4) , 'd' );
|
totalPassed += test_char(totalNumTests, "Testing string_char_at()",
|
||||||
|
string_char_at("Giraffe", 2), 'r');
|
||||||
|
totalPassed += test_char(totalNumTests, "Testing string_char_at()",
|
||||||
|
string_char_at("Armadillo", 4), 'd');
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("There's a ", "natural mystic.") , "There's a natural mystic." );
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("It's the ", "eye of the tiger.") , "It's the eye of the tiger." );
|
string_append("There's a ", "natural mystic."),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("Some", "thing") , "Something" );
|
"There's a natural mystic.");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("", "Nothing to something.") , "Nothing to something." );
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("Not adding anything.", "") , "Not adding anything." );
|
string_append("It's the ", "eye of the tiger."),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_append()", string_append("", "") , "" );
|
"It's the eye of the tiger.");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
|
string_append("Some", "thing"), "Something");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
|
string_append("", "Nothing to something."),
|
||||||
|
"Nothing to something.");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
|
string_append("Not adding anything.", ""),
|
||||||
|
"Not adding anything.");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_append()",
|
||||||
|
string_append("", ""), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("If you carefully.", "listen ", 7) , "If you listen carefully." );
|
totalPassed += test_string(totalNumTests, "Testing string_insert()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("carefully.", "Watch ", 0) , "Watch carefully." );
|
string_insert("If you carefully.", "listen ", 7),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("Iner", "t", 2) , "Inter" );
|
"If you listen carefully.");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("", "TA DA!", 0) , "TA DA!" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("TA DA!", "", 0) , "TA DA!" );
|
test_string(totalNumTests, "Testing string_insert()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_insert()", string_insert("", "", 0) , "" );
|
string_insert("carefully.", "Watch ", 0), "Watch carefully.");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_insert()",
|
||||||
|
string_insert("Iner", "t", 2), "Inter");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_insert()",
|
||||||
|
string_insert("", "TA DA!", 0), "TA DA!");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_insert()",
|
||||||
|
string_insert("TA DA!", "", 0), "TA DA!");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_insert()",
|
||||||
|
string_insert("", "", 0), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'o') , 6 );
|
totalPassed += test_size_t(totalNumTests, "Testing string_find()",
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'e') , 3 );
|
string_find("Have to face reality now.", 'o'), 6);
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'r') , 13 );
|
totalPassed += test_size_t(totalNumTests, "Testing string_find()",
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'a') , 1 );
|
string_find("Have to face reality now.", 'e'), 3);
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'q') , string::npos );
|
totalPassed += test_size_t(totalNumTests, "Testing string_find()",
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("Have to face reality now.", 'h') , string::npos );
|
string_find("Have to face reality now.", 'r'), 13);
|
||||||
totalPassed += test_size_t( totalNumTests, "Testing string_find()", string_find("", '?') , string::npos );
|
totalPassed += test_size_t(totalNumTests, "Testing string_find()",
|
||||||
|
string_find("Have to face reality now.", 'a'), 1);
|
||||||
|
totalPassed +=
|
||||||
|
test_size_t(totalNumTests, "Testing string_find()",
|
||||||
|
string_find("Have to face reality now.", 'q'), string::npos);
|
||||||
|
totalPassed +=
|
||||||
|
test_size_t(totalNumTests, "Testing string_find()",
|
||||||
|
string_find("Have to face reality now.", 'h'), string::npos);
|
||||||
|
totalPassed += test_size_t(totalNumTests, "Testing string_find()",
|
||||||
|
string_find("", '?'), string::npos);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("Such a natural mystic", 7, 7) , "natural" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("Such a natural mystic", 8, 2) , "at" );
|
test_string(totalNumTests, "Testing string_substring()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("Such a natural mystic", 0, 4) , "Such" );
|
string_substring("Such a natural mystic", 7, 7), "natural");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("Something to nothing.", 0, 0) , "" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("Something to nothing.", 10, 0) , "" );
|
test_string(totalNumTests, "Testing string_substring()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substring()", string_substring("", 0, 0) , "" );
|
string_substring("Such a natural mystic", 8, 2), "at");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_substring()",
|
||||||
|
string_substring("Such a natural mystic", 0, 4), "Such");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_substring()",
|
||||||
|
string_substring("Something to nothing.", 0, 0), "");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_substring()",
|
||||||
|
string_substring("Something to nothing.", 10, 0), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_substring()",
|
||||||
|
string_substring("", 0, 0), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("Strings are not the way", "Strings", "Things") , "Things are not the way" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("Strings are not the way", "not the", "the") , "Strings are the way" );
|
totalNumTests, "Testing string_replace()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("Show me the things", "things", "way") , "Show me the way" );
|
string_replace("Strings are not the way", "Strings", "Things"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("Show me the things", "car", "way") , "Show me the things" );
|
"Things are not the way");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("Show me the things", "the ", "") , "Show me things" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("", "now what?", "hmm") , "" );
|
test_string(totalNumTests, "Testing string_replace()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_replace()", string_replace("", "now", "") , "" );
|
string_replace("Strings are not the way", "not the", "the"),
|
||||||
|
"Strings are the way");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_replace()",
|
||||||
|
string_replace("Show me the things", "things", "way"), "Show me the way");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_replace()",
|
||||||
|
string_replace("Show me the things", "car", "way"),
|
||||||
|
"Show me the things");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_replace()",
|
||||||
|
string_replace("Show me the things", "the ", ""),
|
||||||
|
"Show me things");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_replace()",
|
||||||
|
string_replace("", "now what?", "hmm"), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_replace()",
|
||||||
|
string_replace("", "now", ""), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("The quick brown fox jumped over the lazy dog") , "The" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("A man a plan a canal Panama") , "A" );
|
totalNumTests, "Testing string_first_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("I have the hang of this") , "I" );
|
string_first_word("The quick brown fox jumped over the lazy dog"), "The");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("Testing string_first_word()") , "Testing" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("Single") , "Single" );
|
test_string(totalNumTests, "Testing string_first_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("Uh oh") , "Uh" );
|
string_first_word("A man a plan a canal Panama"), "A");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_first_word()", string_first_word("") , "" );
|
totalPassed += test_string(totalNumTests, "Testing string_first_word()",
|
||||||
|
string_first_word("I have the hang of this"), "I");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_first_word()",
|
||||||
|
string_first_word("Testing string_first_word()"), "Testing");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_first_word()",
|
||||||
|
string_first_word("Single"), "Single");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_first_word()",
|
||||||
|
string_first_word("Uh oh"), "Uh");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_first_word()",
|
||||||
|
string_first_word(""), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word()", string_remove_first_word("The quick brown fox jumped over the lazy dog") , "quick brown fox jumped over the lazy dog" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word()", string_remove_first_word("Testing string_remove_first_word()") , "string_remove_first_word()" );
|
totalNumTests, "Testing string_remove_first_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word()", string_remove_first_word("Goodbye") , "" );
|
string_remove_first_word("The quick brown fox jumped over the lazy dog"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word()", string_remove_first_word("") , "" );
|
"quick brown fox jumped over the lazy dog");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word() twice",string_remove_first_word(string_remove_first_word("The quick brown fox jumped over the lazy dog")) , "brown fox jumped over the lazy dog" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word() twice",string_remove_first_word("Testing string_remove_first_word()") , "" );
|
totalNumTests, "Testing string_remove_first_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_remove_first_word() twice",string_remove_first_word(string_remove_first_word("Goodbye")) , "" );
|
string_remove_first_word("Testing string_remove_first_word()"),
|
||||||
|
"string_remove_first_word()");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_remove_first_word()",
|
||||||
|
string_remove_first_word("Goodbye"), "");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_remove_first_word()",
|
||||||
|
string_remove_first_word(""), "");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_remove_first_word() twice",
|
||||||
|
string_remove_first_word(string_remove_first_word(
|
||||||
|
"The quick brown fox jumped over the lazy dog")),
|
||||||
|
"brown fox jumped over the lazy dog");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_remove_first_word() twice",
|
||||||
|
string_remove_first_word(string_remove_first_word(
|
||||||
|
"Testing string_remove_first_word()")),
|
||||||
|
"");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_remove_first_word() twice",
|
||||||
|
string_remove_first_word(string_remove_first_word("Goodbye")), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("The quick brown fox jumped over the lazy dog") , "quick" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("A man a plan a canal Panama") , "man" );
|
totalNumTests, "Testing string_second_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("Testing string_second_word()") , "string_second_word()" );
|
string_second_word("The quick brown fox jumped over the lazy dog"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("I have the hang of this") , "have" );
|
"quick");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("Uh oh") , "oh" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("Single") , "" );
|
test_string(totalNumTests, "Testing string_second_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_second_word()", string_second_word("") , "" );
|
string_second_word("A man a plan a canal Panama"), "man");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_second_word()",
|
||||||
|
string_second_word("Testing string_second_word()"),
|
||||||
|
"string_second_word()");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_second_word()",
|
||||||
|
string_second_word("I have the hang of this"), "have");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_second_word()",
|
||||||
|
string_second_word("Uh oh"), "oh");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_second_word()",
|
||||||
|
string_second_word("Single"), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_second_word()",
|
||||||
|
string_second_word(""), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("The quick brown fox jumped over the lazy dog") , "brown" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("A man a plan a canal Panama") , "a" );
|
totalNumTests, "Testing string_third_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("I have the hang of this") , "the" );
|
string_third_word("The quick brown fox jumped over the lazy dog"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("Uh oh no") , "no" );
|
"brown");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("Uh oh") , "" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("Single") , "" );
|
test_string(totalNumTests, "Testing string_third_word()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_third_word()", string_third_word("") , "" );
|
string_third_word("A man a plan a canal Panama"), "a");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_third_word()",
|
||||||
|
string_third_word("I have the hang of this"), "the");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_third_word()",
|
||||||
|
string_third_word("Uh oh no"), "no");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_third_word()",
|
||||||
|
string_third_word("Uh oh"), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_third_word()",
|
||||||
|
string_third_word("Single"), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_third_word()",
|
||||||
|
string_third_word(""), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(1)", string_nth_word("The quick brown fox jumped over the lazy dog", 1) , "The" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(2)", string_nth_word("The quick brown fox jumped over the lazy dog", 2) , "quick" );
|
totalNumTests, "Testing string_nth_word(1)",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(3)", string_nth_word("The quick brown fox jumped over the lazy dog", 3) , "brown" );
|
string_nth_word("The quick brown fox jumped over the lazy dog", 1),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(4)", string_nth_word("The quick brown fox jumped over the lazy dog", 4) , "fox" );
|
"The");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(5)", string_nth_word("The quick brown fox jumped over the lazy dog", 5) , "jumped" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(6)", string_nth_word("The quick brown fox jumped over the lazy dog", 6) , "over" );
|
totalNumTests, "Testing string_nth_word(2)",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(7)", string_nth_word("The quick brown fox jumped over the lazy dog", 7) , "the" );
|
string_nth_word("The quick brown fox jumped over the lazy dog", 2),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(8)", string_nth_word("The quick brown fox jumped over the lazy dog", 8) , "lazy" );
|
"quick");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(9)", string_nth_word("The quick brown fox jumped over the lazy dog", 9) , "dog" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(10)", string_nth_word("The quick brown fox jumped over the lazy dog", 10) , "" );
|
totalNumTests, "Testing string_nth_word(3)",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(11)", string_nth_word("The quick brown fox jumped over the lazy dog", 11) , "" );
|
string_nth_word("The quick brown fox jumped over the lazy dog", 3),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(1)", string_nth_word("", 1) , "" );
|
"brown");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(2)", string_nth_word("", 2) , "" );
|
totalPassed += test_string(
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(3)", string_nth_word("", 3) , "" );
|
totalNumTests, "Testing string_nth_word(4)",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_nth_word(10)", string_nth_word("", 10) , "" );
|
string_nth_word("The quick brown fox jumped over the lazy dog", 4),
|
||||||
|
"fox");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(5)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 5),
|
||||||
|
"jumped");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(6)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 6),
|
||||||
|
"over");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(7)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 7),
|
||||||
|
"the");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(8)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 8),
|
||||||
|
"lazy");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(9)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 9),
|
||||||
|
"dog");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(10)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 10), "");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_nth_word(11)",
|
||||||
|
string_nth_word("The quick brown fox jumped over the lazy dog", 11), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_nth_word(1)",
|
||||||
|
string_nth_word("", 1), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_nth_word(2)",
|
||||||
|
string_nth_word("", 2), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_nth_word(3)",
|
||||||
|
string_nth_word("", 3), "");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_nth_word(10)",
|
||||||
|
string_nth_word("", 10), "");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
vector<string> tokens1 = {"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"};
|
vector<string> tokens1 = {"The", "quick", "brown", "fox", "jumped",
|
||||||
totalPassed += test_vector_string( totalNumTests, "Testing string_tokenize()", string_tokenize("The quick brown fox jumped over the lazy dog", ' '), tokens1 );
|
"over", "the", "lazy", "dog"};
|
||||||
totalPassed += test_vector_string( totalNumTests, "Testing string_tokenize()", string_tokenize("The@quick@brown@fox@jumped@over@the@lazy@dog", '@'), tokens1 );
|
totalPassed += test_vector_string(
|
||||||
|
totalNumTests, "Testing string_tokenize()",
|
||||||
|
string_tokenize("The quick brown fox jumped over the lazy dog", ' '),
|
||||||
|
tokens1);
|
||||||
|
totalPassed += test_vector_string(
|
||||||
|
totalNumTests, "Testing string_tokenize()",
|
||||||
|
string_tokenize("The@quick@brown@fox@jumped@over@the@lazy@dog", '@'),
|
||||||
|
tokens1);
|
||||||
|
|
||||||
vector<string> tokens2 = {"The quick brown fox jumped over the lazy dog"};
|
vector<string> tokens2 = {"The quick brown fox jumped over the lazy dog"};
|
||||||
totalPassed += test_vector_string( totalNumTests, "Testing string_tokenize()", string_tokenize("The quick brown fox jumped over the lazy dog", '*'), tokens2 );
|
totalPassed += test_vector_string(
|
||||||
|
totalNumTests, "Testing string_tokenize()",
|
||||||
|
string_tokenize("The quick brown fox jumped over the lazy dog", '*'),
|
||||||
|
tokens2);
|
||||||
|
|
||||||
vector<string> tokens3 = {""};
|
vector<string> tokens3 = {""};
|
||||||
totalPassed += test_vector_string( totalNumTests, "Testing string_tokenize()", string_tokenize("", '*'), tokens3 );
|
totalPassed += test_vector_string(totalNumTests, "Testing string_tokenize()",
|
||||||
|
string_tokenize("", '*'), tokens3);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substitute()", string_substitute("The Gxxgle", 'x', 'o') , "The Google" );
|
totalPassed +=
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substitute()", string_substitute("$chool of Mine$", '$', 's') , "school of Mines" );
|
test_string(totalNumTests, "Testing string_substitute()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substitute()", string_substitute("$chool of Mine$", '+', '*') , "$chool of Mine$" );
|
string_substitute("The Gxxgle", 'x', 'o'), "The Google");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_substitute() twice", string_substitute(string_substitute("D--", '-', '+'), 'D', 'C') , "C++" );
|
totalPassed += test_string(totalNumTests, "Testing string_substitute()",
|
||||||
|
string_substitute("$chool of Mine$", '$', 's'),
|
||||||
|
"school of Mines");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_substitute()",
|
||||||
|
string_substitute("$chool of Mine$", '+', '*'),
|
||||||
|
"$chool of Mine$");
|
||||||
|
totalPassed += test_string(
|
||||||
|
totalNumTests, "Testing string_substitute() twice",
|
||||||
|
string_substitute(string_substitute("D--", '-', '+'), 'D', 'C'), "C++");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_lower()", string_to_lower("This SHOULD be LOWER case") , "this should be lower case" );
|
totalPassed += test_string(totalNumTests, "Testing string_to_lower()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_lower()", string_to_lower("MNASDF874792L[]//.;[\t],") , "mnasdf874792l[]//.;[\t]," );
|
string_to_lower("This SHOULD be LOWER case"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_lower()", string_to_lower("C++") , "c++" );
|
"this should be lower case");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_lower()", string_to_lower("this is already lower case") , "this is already lower case" );
|
totalPassed += test_string(totalNumTests, "Testing string_to_lower()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_lower()", string_to_lower("1234567890,./;'[]") , "1234567890,./;'[]" );
|
string_to_lower("MNASDF874792L[]//.;[\t],"),
|
||||||
|
"mnasdf874792l[]//.;[\t],");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_to_lower()",
|
||||||
|
string_to_lower("C++"), "c++");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_to_lower()",
|
||||||
|
string_to_lower("this is already lower case"),
|
||||||
|
"this is already lower case");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_to_lower()",
|
||||||
|
string_to_lower("1234567890,./;'[]"), "1234567890,./;'[]");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_upper()", string_to_upper("This SHOULD be upper case") , "THIS SHOULD BE UPPER CASE" );
|
totalPassed += test_string(totalNumTests, "Testing string_to_upper()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_upper()", string_to_upper("mnasdf874792l[]//.;[\t],") , "MNASDF874792L[]//.;[\t]," );
|
string_to_upper("This SHOULD be upper case"),
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_upper()", string_to_upper("c++") , "C++" );
|
"THIS SHOULD BE UPPER CASE");
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_upper()", string_to_upper("THIS IS ALREADY UPPER CASE") , "THIS IS ALREADY UPPER CASE" );
|
totalPassed += test_string(totalNumTests, "Testing string_to_upper()",
|
||||||
totalPassed += test_string( totalNumTests, "Testing string_to_upper()", string_to_upper("1234567890,./;'[]") , "1234567890,./;'[]" );
|
string_to_upper("mnasdf874792l[]//.;[\t],"),
|
||||||
|
"MNASDF874792L[]//.;[\t],");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_to_upper()",
|
||||||
|
string_to_upper("c++"), "C++");
|
||||||
|
totalPassed += test_string(totalNumTests, "Testing string_to_upper()",
|
||||||
|
string_to_upper("THIS IS ALREADY UPPER CASE"),
|
||||||
|
"THIS IS ALREADY UPPER CASE");
|
||||||
|
totalPassed +=
|
||||||
|
test_string(totalNumTests, "Testing string_to_upper()",
|
||||||
|
string_to_upper("1234567890,./;'[]"), "1234567890,./;'[]");
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("C++", "c++") , -1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("C++", "C++") , 0 );
|
string_compare("C++", "c++"), -1);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("c++", "c++") , 0 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("c++", "C++") , 1 );
|
string_compare("C++", "C++"), 0);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("short", "shorter") , -1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("longer", "long") , 1 );
|
string_compare("c++", "c++"), 0);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("after", "later") , -1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("later", "after") , 1 );
|
string_compare("c++", "C++"), 1);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("G", "g") , -1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("g", "G") , 1 );
|
string_compare("short", "shorter"), -1);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("GoOse", "Bye") , 1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("Equal", "Equal") , 0 );
|
string_compare("longer", "long"), 1);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("Not Empty", "") , 1 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("", "Not Empty") , -1 );
|
string_compare("after", "later"), -1);
|
||||||
totalPassed += test_int( totalNumTests, "Testing string_compare()", string_compare("", "") , 0 );
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("later", "after"), 1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("G", "g"), -1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("g", "G"), 1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("GoOse", "Bye"), 1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("Equal", "Equal"), 0);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("Not Empty", ""), 1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("", "Not Empty"), -1);
|
||||||
|
totalPassed += test_int(totalNumTests, "Testing string_compare()",
|
||||||
|
string_compare("", ""), 0);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << "Tests Passed: " << setw(3) << right << totalPassed << " / " << setw(3) << totalNumTests << " (" << setprecision(0) << fixed << totalPassed * 100.0f / totalNumTests << "%)" << endl << endl;
|
cout << "Tests Passed: " << setw(3) << right << totalPassed << " / "
|
||||||
|
<< setw(3) << totalNumTests << " (" << setprecision(0) << fixed
|
||||||
|
<< totalPassed * 100.0f / totalNumTests << "%)" << endl
|
||||||
|
<< endl;
|
||||||
|
|
||||||
return (totalPassed == totalNumTests);
|
return (totalPassed == totalNumTests);
|
||||||
}
|
}
|
16
test_suite.h
16
test_suite.h
|
@ -20,7 +20,8 @@ bool run_all_tests();
|
||||||
* @param RHS expected result
|
* @param RHS expected result
|
||||||
* @return 1 if test passed, 0 otherwise
|
* @return 1 if test passed, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int test_int(int& testNum, const std::string MESSAGE, const int LHS, const int RHS);
|
int test_int(int& testNum, const std::string MESSAGE, const int LHS,
|
||||||
|
const int RHS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
||||||
|
@ -32,7 +33,8 @@ int test_int(int& testNum, const std::string MESSAGE, const int LHS, const int R
|
||||||
* @param RHS expected result
|
* @param RHS expected result
|
||||||
* @return 1 if test passed, 0 otherwise
|
* @return 1 if test passed, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int test_unsigned_long(int& testNum, const std::string MESSAGE, const unsigned long LHS, const unsigned long RHS);
|
int test_unsigned_long(int& testNum, const std::string MESSAGE,
|
||||||
|
const unsigned long LHS, const unsigned long RHS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
||||||
|
@ -44,7 +46,8 @@ int test_unsigned_long(int& testNum, const std::string MESSAGE, const unsigned l
|
||||||
* @param RHS expected result
|
* @param RHS expected result
|
||||||
* @return 1 if test passed, 0 otherwise
|
* @return 1 if test passed, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int test_char(int& testNum, const std::string MESSAGE, const char LHS, const char RHS);
|
int test_char(int& testNum, const std::string MESSAGE, const char LHS,
|
||||||
|
const char RHS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
||||||
|
@ -56,7 +59,8 @@ int test_char(int& testNum, const std::string MESSAGE, const char LHS, const cha
|
||||||
* @param RHS expected result
|
* @param RHS expected result
|
||||||
* @return 1 if test passed, 0 otherwise
|
* @return 1 if test passed, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int test_string(int& testNum, const std::string MESSAGE, const std::string LHS, const std::string RHS);
|
int test_string(int& testNum, const std::string MESSAGE, const std::string LHS,
|
||||||
|
const std::string RHS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
* @brief A generic test function, that simply prints "PASSED" if LHS equals RHS
|
||||||
|
@ -68,6 +72,8 @@ int test_string(int& testNum, const std::string MESSAGE, const std::string LHS,
|
||||||
* @param RHS expected result
|
* @param RHS expected result
|
||||||
* @return 1 if test passed, 0 otherwise
|
* @return 1 if test passed, 0 otherwise
|
||||||
*/
|
*/
|
||||||
int test_vector_string(int& testNum, const std::string MESSAGE, const std::vector<std::string>& LHS, const std::vector<std::string>& RHS);
|
int test_vector_string(int& testNum, const std::string MESSAGE,
|
||||||
|
const std::vector<std::string>& LHS,
|
||||||
|
const std::vector<std::string>& RHS);
|
||||||
|
|
||||||
#endif
|
#endif
|
BIN
test_suite.o
BIN
test_suite.o
Binary file not shown.
Loading…
Reference in a new issue