Skip to content

Commit 9e938b8

Browse files
committed
Added test case for Utilities::IsInMap()
1 parent a9ff893 commit 9e938b8

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

XMapLibTest/TestMapFunctions.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
#include "pch.h"
3+
#include "CppUnitTest.h"
4+
#include "../XMapLib/MapFunctions.h"
5+
6+
namespace XMapLibTest
7+
{
8+
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
9+
TEST_CLASS(TestMapFunctions)
10+
{
11+
public:
12+
TEST_METHOD(TestSearchMap)
13+
{
14+
using namespace sds;
15+
using namespace std;
16+
Logger::WriteMessage("Begin TestSetMapInfo()");
17+
const wstring one{ L"one" };
18+
const wstring two{ L"two" };
19+
const wstring three{ L"three" };
20+
const map<wstring, int> testMap{ {one,1}, {two,2}, {three,3} };
21+
auto TestFound = [&](const wstring key, const int value)
22+
{
23+
24+
int outValue = 0;
25+
const wstring message = L"asserting key " + key + L" is found in the map.";
26+
std::wstringstream ws;
27+
ws << L"asserting value " << value << L" is found in the map.";
28+
const wstring valueMessage = ws.str();
29+
Assert::IsTrue(Utilities::MapFunctions::IsInMap(key, testMap, outValue), message.c_str());
30+
Assert::AreEqual(outValue, value, valueMessage.c_str());
31+
};
32+
TestFound(one, 1);
33+
TestFound(two, 2);
34+
TestFound(three, 3);
35+
const wstring notFound = L"not found key";
36+
int result = 0;
37+
Assert::IsFalse(Utilities::MapFunctions::IsInMap(notFound, testMap, result), L"Testing key definitely not in map returns false.");
38+
Assert::AreEqual(result, 0, L"Testing reference arg still 0 after not found in map.");
39+
Logger::WriteMessage("End TestSetMapInfo()");
40+
}
41+
};
42+
43+
}

XMapLibTest/XMapLibTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "TestSensitivityMap.h"
88
#include "TestMouse.h"
99
#include "TestThumbstickToDelay.h"
10+
#include "TestMapFunctions.h"
1011
#include "../XMapLib/MouseSettings.h"
1112

1213
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

XMapLibTest/XMapLibTest.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
<ItemGroup>
182182
<ClInclude Include="pch.h" />
183183
<ClInclude Include="TemplatesForTest.h" />
184+
<ClInclude Include="TestMapFunctions.h" />
184185
<ClInclude Include="TestMapper.h" />
185186
<ClInclude Include="TestMouse.h" />
186187
<ClInclude Include="TestSensitivityMap.h" />

XMapLibTest/XMapLibTest.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@
4141
<ClInclude Include="TestThumbstickToDelay.h">
4242
<Filter>Header Files</Filter>
4343
</ClInclude>
44+
<ClInclude Include="TestMapFunctions.h">
45+
<Filter>Header Files</Filter>
46+
</ClInclude>
4447
</ItemGroup>
4548
</Project>

0 commit comments

Comments
 (0)