From 29013b27062df56bd18a7c22eb8f7f89731f7852 Mon Sep 17 00:00:00 2001 From: anuran Date: Mon, 4 Oct 2021 02:36:54 +0530 Subject: [PATCH] Added tests --- .gitignore | 2 +- .vscode/settings.json | 2 +- search/text_search.cpp | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5275088d0..12318c6cd 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,4 @@ a.out *.out *.app -build/ +build/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 074c4ab03..245be1a04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,4 +3,4 @@ "editor.formatOnSave": true, "editor.formatOnType": true, "editor.formatOnPaste": true -} +} \ No newline at end of file diff --git a/search/text_search.cpp b/search/text_search.cpp index ae6128bf2..ece2ef6d5 100644 --- a/search/text_search.cpp +++ b/search/text_search.cpp @@ -2,6 +2,7 @@ * \file * \brief Search for words in a long textual paragraph. */ +#include #include #include #ifdef _MSC_VER @@ -24,10 +25,13 @@ std::string lower(std::string word) { return lc; } +void test() { assert(lower("abcd").compare("abcd") == 0); } + int main() { + test(); // Testing the lower() function. std::string paragraph; std::cout << "Please enter your paragraph: \n"; - getline(std::cin, paragraph); + std::getline(std::cin, paragraph); std::cout << "\nHello, your paragraph is:\n " << paragraph << "!\n"; std::cout << "\nThe size of your paragraph = " << paragraph.size() << " characters. \n\n"; @@ -39,7 +43,7 @@ int main() { while (true) { std::string word; std::cout << "Please enter the word you are searching for: "; - getline(std::cin, word); + std::getline(std::cin, word); std::cout << "Ignore case? 1 = Yes, 0 = No" << std::endl; std::cin >> ch; if (ch == 1) {