diff options
Diffstat (limited to 'StringTools/Test')
| -rw-r--r-- | StringTools/Test/Replace_Char.cpp | 166 | ||||
| -rw-r--r-- | StringTools/Test/Replace_String.cpp | 180 | ||||
| -rw-r--r-- | StringTools/Test/Test.cpp | 16 | ||||
| -rw-r--r-- | StringTools/Test/Test.vcxproj | 22 | ||||
| -rw-r--r-- | StringTools/Test/Test.vcxproj.filters | 9 |
5 files changed, 358 insertions, 35 deletions
diff --git a/StringTools/Test/Replace_Char.cpp b/StringTools/Test/Replace_Char.cpp new file mode 100644 index 0000000..d562651 --- /dev/null +++ b/StringTools/Test/Replace_Char.cpp @@ -0,0 +1,166 @@ +#include "CppUnitTest.h"
+#include "../StringTools/StringTools.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace _StringTools
+{
+ TEST_CLASS(_Replace_Char)
+ {
+ 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, 'a', "Subst");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "");
+ return;
+ }
+
+ // Tests that replacing a char to an empty string works
+ TEST_METHOD(Single_ReplaceToEmpty)
+ {
+ // Setup
+ const std::string in = "i";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'i', "");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "");
+ return;
+ }
+
+ // Tests that replacing to a single char works
+ TEST_METHOD(Single_ReplaceToSingleChar)
+ {
+ // Setup
+ const std::string in = "a";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'a', "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, 'a', 'i');
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "Oilbinger");
+ return;
+ }
+
+ // Tests that replacing the find to something longer works
+ TEST_METHOD(Single_ReplaceToLonger)
+ {
+ // Setup
+ const std::string in = "Littled";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'd', "binger");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "Littlebinger");
+ return;
+ }
+
+ // Tests that replacing a char to an empty string works
+ TEST_METHOD(Multiple_ReplaceToEmpty)
+ {
+ // Setup
+ const std::string in = "dirty dogs dig dirt daringly";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'd', "");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "irty ogs ig irt aringly");
+ return;
+ }
+
+ // Tests that replacing to a single char works
+ TEST_METHOD(Multiple_ReplaceToSingleChar)
+ {
+ // Setup
+ const std::string in = "Oilbanger, Bangerfanger, Lattle brattle oaly skattle.";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'a', "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 = "Oilbanger, Bangerfanger, Lattle brattle oaly skattle.";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'a', '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 = "d d d d d d d d";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'd', "bla");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "bla bla bla bla bla bla bla bla");
+ return;
+ }
+
+ // Tests that the replacer ignores chars put in by the replacer
+ TEST_METHOD(ReplacerIgnoresReplaced)
+ {
+ // Setup
+ const std::string in = "b b b b b b b b";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'b', "bla");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "bla bla bla bla bla bla bla bla");
+ return;
+ }
+
+ // Tests that replacing succesive findings works
+ TEST_METHOD(Replace_Successive)
+ {
+ // Setup
+ const std::string in = "bbbbbbbb";
+
+ // Exercise
+ const std::string out = StringTools::Replace(in, 'b', "bla");
+
+ // Verify
+ Assert::AreEqual(out.c_str(), "blablablablablablablabla");
+ return;
+ }
+ };
+}
diff --git a/StringTools/Test/Replace_String.cpp b/StringTools/Test/Replace_String.cpp new file mode 100644 index 0000000..ff67ac4 --- /dev/null +++ b/StringTools/Test/Replace_String.cpp @@ -0,0 +1,180 @@ +#include "CppUnitTest.h"
+#include "../StringTools/StringTools.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+namespace _StringTools
+{
+ 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;
+ }
+ };
+}
diff --git a/StringTools/Test/Test.cpp b/StringTools/Test/Test.cpp deleted file mode 100644 index 4441b10..0000000 --- a/StringTools/Test/Test.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "pch.h"
-#include "CppUnitTest.h"
-
-using namespace Microsoft::VisualStudio::CppUnitTestFramework;
-
-namespace Test
-{
- TEST_CLASS(Test)
- {
- public:
-
- TEST_METHOD(TestMethod1)
- {
- }
- };
-}
diff --git a/StringTools/Test/Test.vcxproj b/StringTools/Test/Test.vcxproj index d60a246..51fba2c 100644 --- a/StringTools/Test/Test.vcxproj +++ b/StringTools/Test/Test.vcxproj @@ -25,6 +25,7 @@ <RootNamespace>Test</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
+ <ProjectName>Test_Stringtools</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -89,7 +90,7 @@ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -104,7 +105,7 @@ </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -119,7 +120,7 @@ </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -138,7 +139,7 @@ </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -156,16 +157,13 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="pch.cpp">
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
- </ClCompile>
- <ClCompile Include="Test.cpp" />
+ <ProjectReference Include="..\StringTools\StringTools.vcxproj">
+ <Project>{0270ac5e-eba3-4d8f-8d50-995fd44959b4}</Project>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="pch.h" />
+ <ClCompile Include="Replace_Char.cpp" />
+ <ClCompile Include="Replace_String.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/StringTools/Test/Test.vcxproj.filters b/StringTools/Test/Test.vcxproj.filters index 99bfffa..e159865 100644 --- a/StringTools/Test/Test.vcxproj.filters +++ b/StringTools/Test/Test.vcxproj.filters @@ -15,16 +15,11 @@ </Filter>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="Test.cpp">
+ <ClCompile Include="Replace_Char.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
- <ClCompile Include="pch.cpp">
+ <ClCompile Include="Replace_String.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
- <ItemGroup>
- <ClInclude Include="pch.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- </ItemGroup>
</Project>
\ No newline at end of file |
