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+ }
0 commit comments