From a516b3aa6f6906d6780172d684e91fa4b7d3cdd1 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Fri, 11 Feb 2022 01:32:43 +0100 Subject: Switched to Catch2 testing framework --- StringTools/Test/Replace_String.cpp | 342 +++++++++++++++++------------------- 1 file changed, 166 insertions(+), 176 deletions(-) (limited to 'StringTools/Test/Replace_String.cpp') diff --git a/StringTools/Test/Replace_String.cpp b/StringTools/Test/Replace_String.cpp index ff67ac4..cdef64a 100644 --- a/StringTools/Test/Replace_String.cpp +++ b/StringTools/Test/Replace_String.cpp @@ -1,180 +1,170 @@ -#include "CppUnitTest.h" -#include "../StringTools/StringTools.h" +#include +#include "Catch2.h" -using namespace Microsoft::VisualStudio::CppUnitTestFramework; +// Tests that replacing something in an empty string returns an empty string +TEST_CASE(__FILE__"/EmptyString") +{ + // Setup + const std::string in = ""; + + // Exercise + const std::string out = StringTools::Replace(in, "burger", "Subst"); + + // Verify + REQUIRE(out == ""); + return; +} + +// Tests that replacing a string to an empty string works +TEST_CASE(__FILE__"/Single_ReplaceToEmpty") +{ + // Setup + const std::string in = "Squarepants"; + + // Exercise + const std::string out = StringTools::Replace(in, "Squarepants", ""); + + // Verify + REQUIRE(out == ""); + return; +} + +// Tests that replacing to a single char works +TEST_CASE(__FILE__"/Single_ReplaceToSingleChar") +{ + // Setup + const std::string in = "Squarepants"; + + // Exercise + const std::string out = StringTools::Replace(in, "Squarepants", "i"); + + // Verify + REQUIRE(out == "i"); + return; +} + +// Tests that replacing to a single char works, passing a char +TEST_CASE(__FILE__"/Single_ReplaceToSingleChar_AsChar") +{ + // Setup + const std::string in = "Oilbanger"; + + // Exercise + const std::string out = StringTools::Replace(in, "Oilbanger", 'i'); + + // Verify + REQUIRE(out == "i"); + return; +} + +// Tests that replacing the find to something longer works +TEST_CASE(__FILE__"/Single_ReplaceToLonger") +{ + // Setup + const std::string in = "LittleDong"; + + // Exercise + const std::string out = StringTools::Replace(in, "Dong", "Binger"); + + // Verify + REQUIRE(out == "LittleBinger"); + return; +} + +// Tests that replacing a string to an empty string works +TEST_CASE(__FILE__"/Multiple_ReplaceToEmpty") +{ + // Setup + const std::string in = "The fucking dogs are fucking eating the fucking chicken."; + + // Exercise + const std::string out = StringTools::Replace(in, "fucking ", ""); + + // Verify + REQUIRE(out == "The dogs are eating the chicken."); + return; +} + +// Tests that replacing to a single char works +TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar") +{ + // Setup + const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle."; + + // Exercise + const std::string out = StringTools::Replace(in, "smeary", "i"); + + // Verify + REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle."); + return; +} + +// Tests that replacing to a single char works, passing a char +TEST_CASE(__FILE__"/Multiple_ReplaceToSingleChar_AsChar") +{ + // Setup + const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle."; + + // Exercise + const std::string out = StringTools::Replace(in, "smeary", 'i'); + + // Verify + REQUIRE(out == "Oilbinger, Bingerfinger, Little brittle oily skittle."); + return; +} + +// Tests that replacing the find to something longer works +TEST_CASE(__FILE__"/Multiple_ReplaceToLonger") +{ + // Setup + const std::string in = "honk honk honk honk honk honk honk honk"; + + // Exercise + const std::string out = StringTools::Replace(in, "honk", "hallery"); -namespace _StringTools + // Verify + REQUIRE(out == "hallery hallery hallery hallery hallery hallery hallery hallery"); + return; +} + +// Tests that the replacer ignores chars put in by the replacer +TEST_CASE(__FILE__"/ReplacerIgnoresReplaced") +{ + // Setup + const std::string in = "honk honk honk honk honk honk honk honk"; + + // Exercise + const std::string out = StringTools::Replace(in, "honk", "honka"); + + // Verify + REQUIRE(out == "honka honka honka honka honka honka honka honka"); + return; +} + +// Tests that replacing successive findings works +TEST_CASE(__FILE__"/Replace_Successive") { - TEST_CLASS(_Replace_String) - { - public: - - // Tests that replacing something in an empty string returns an empty string - TEST_METHOD(EmptyString) - { - // Setup - const std::string in = ""; - - // Exercise - const std::string out = StringTools::Replace(in, "burger", "Subst"); - - // Verify - Assert::AreEqual(out.c_str(), ""); - return; - } - - // Tests that replacing a string to an empty string works - TEST_METHOD(Single_ReplaceToEmpty) - { - // Setup - const std::string in = "Squarepants"; - - // Exercise - const std::string out = StringTools::Replace(in, "Squarepants", ""); - - // Verify - Assert::AreEqual(out.c_str(), ""); - return; - } - - // Tests that replacing to a single char works - TEST_METHOD(Single_ReplaceToSingleChar) - { - // Setup - const std::string in = "Squarepants"; - - // Exercise - const std::string out = StringTools::Replace(in, "Squarepants", "i"); - - // Verify - Assert::AreEqual(out.c_str(), "i"); - return; - } - - // Tests that replacing to a single char works, passing a char - TEST_METHOD(Single_ReplaceToSingleChar_AsChar) - { - // Setup - const std::string in = "Oilbanger"; - - // Exercise - const std::string out = StringTools::Replace(in, "Oilbanger", 'i'); - - // Verify - Assert::AreEqual(out.c_str(), "i"); - return; - } - - // Tests that replacing the find to something longer works - TEST_METHOD(Single_ReplaceToLonger) - { - // Setup - const std::string in = "LittleDong"; - - // Exercise - const std::string out = StringTools::Replace(in, "Dong", "Binger"); - - // Verify - Assert::AreEqual(out.c_str(), "LittleBinger"); - return; - } - - // Tests that replacing a string to an empty string works - TEST_METHOD(Multiple_ReplaceToEmpty) - { - // Setup - const std::string in = "The fucking dogs are fucking eating the fucking chicken."; - - // Exercise - const std::string out = StringTools::Replace(in, "fucking ", ""); - - // Verify - Assert::AreEqual(out.c_str(), "The dogs are eating the chicken."); - return; - } - - // Tests that replacing to a single char works - TEST_METHOD(Multiple_ReplaceToSingleChar) - { - // Setup - const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle."; - - // Exercise - const std::string out = StringTools::Replace(in, "smeary", "i"); - - // Verify - Assert::AreEqual(out.c_str(), "Oilbinger, Bingerfinger, Little brittle oily skittle."); - return; - } - - // Tests that replacing to a single char works, passing a char - TEST_METHOD(Multiple_ReplaceToSingleChar_AsChar) - { - // Setup - const std::string in = "Oilbsmearynger, Bsmearyngerfsmearynger, Lsmearyttle brsmearyttle osmearyly sksmearyttle."; - - // Exercise - const std::string out = StringTools::Replace(in, "smeary", 'i'); - - // Verify - Assert::AreEqual(out.c_str(), "Oilbinger, Bingerfinger, Little brittle oily skittle."); - return; - } - - // Tests that replacing the find to something longer works - TEST_METHOD(Multiple_ReplaceToLonger) - { - // Setup - const std::string in = "honk honk honk honk honk honk honk honk"; - - // Exercise - const std::string out = StringTools::Replace(in, "honk", "hallery"); - - // Verify - Assert::AreEqual(out.c_str(), "hallery hallery hallery hallery hallery hallery hallery hallery"); - return; - } - - // Tests that the replacer ignores chars put in by the replacer - TEST_METHOD(ReplacerIgnoresReplaced) - { - // Setup - const std::string in = "honk honk honk honk honk honk honk honk"; - - // Exercise - const std::string out = StringTools::Replace(in, "honk", "honka"); - - // Verify - Assert::AreEqual(out.c_str(), "honka honka honka honka honka honka honka honka"); - return; - } - - // Tests that replacing succesive findings works - TEST_METHOD(Replace_Successive) - { - // Setup - const std::string in = "honkhonkhonkhonkhonkhonkhonkhonk"; - - // Exercise - const std::string out = StringTools::Replace(in, "honk", "hallery"); - - // Verify - Assert::AreEqual(out.c_str(), "halleryhalleryhalleryhalleryhalleryhalleryhalleryhallery"); - return; - } - - // Tests that if find.length() == 0, it returns just the input - TEST_METHOD(Find_Length0_Returns_Input) - { - // Setup - const std::string in = "Littled"; - - // Exercise - const std::string out = StringTools::Replace(in, "", "binger"); - - // Verify - Assert::AreEqual(out.c_str(), "Littled"); - return; - } - }; + // Setup + const std::string in = "honkhonkhonkhonkhonkhonkhonkhonk"; + + // Exercise + const std::string out = StringTools::Replace(in, "honk", "hallery"); + + // Verify + REQUIRE(out == "halleryhalleryhalleryhalleryhalleryhalleryhalleryhallery"); + return; +} + +// Tests that if find.length() == 0, it returns just the input +TEST_CASE(__FILE__"/Find_Length0_Returns_Input") +{ + // Setup + const std::string in = "Littled"; + + // Exercise + const std::string out = StringTools::Replace(in, "", "binger"); + + // Verify + REQUIRE(out == "Littled"); + return; } -- cgit v1.2.3