diff --git a/TinySTL/Test/PairTest.cpp b/TinySTL/Test/PairTest.cpp index 01fe5fc..540d4a0 100644 --- a/TinySTL/Test/PairTest.cpp +++ b/TinySTL/Test/PairTest.cpp @@ -1,44 +1,64 @@ -#include +#include "PairTest.h" -#include "..\Utility.h" -#include "..\String.h" - -using namespace TinySTL; - -void testPair(){ - // test ctor - pair product1; // default constructor - pair product2("tomatoes", 2.30); // value init - pair product3(product2); // copy constructor - product1 = make_pair(string("lightbulbs"), 0.99); // using make_pair (move) - product2.first = "shoes"; // the type of first is string - product2.second = 39.90; // the type of second is double - std::cout << "The price of " << product1.first << " is $" << product1.second << '\n'; - std::cout << "The price of " << product2.first << " is $" << product2.second << '\n'; - std::cout << "The price of " << product3.first << " is $" << product3.second << '\n'; - - //test operator = - pair planet, homeplanet; - planet = make_pair(string("Earth"), 6371); - homeplanet = planet; - std::cout << "Home planet: " << homeplanet.first << '\n'; - std::cout << "Planet size: " << homeplanet.second << '\n'; - - //test swap - pair foo1(10, 'a'); - pair bar1(90, 'z'); - //foo1.swap(bar1); - swap(foo1, bar1); - std::cout << "foo contains: " << foo1.first; - std::cout << " and " << foo1.second << '\n'; - - //test relational operators - pair foo(10, 'z'); - pair bar(90, 'a'); - if (foo == bar) std::cout << "foo and bar are equal\n"; - if (foo != bar) std::cout << "foo and bar are not equal\n"; - if (foo< bar) std::cout << "foo is less than bar\n"; - if (foo> bar) std::cout << "foo is greater than bar\n"; - if (foo <= bar) std::cout << "foo is less than or equal to bar\n"; - if (foo >= bar) std::cout << "foo is greater than or equal to bar\n"; -} \ No newline at end of file +namespace TinySTL{ + namespace PairTest{ + template + static inline bool container_equal(const Container1& pair1, const Container2& pair2){ + return (pair1.first == pair2.first && pair1.second == pair2.second); + } + void testCase1(){ + stdPair p1(5, 5); + tsPair p2(5, 5); + assert(container_equal(p1, p2)); + } + void testCase2(){ + stdPair p1(stdPair(0, 0)); + tsPair p2(tsPair(0, 0)); + assert(container_equal(p1, p2)); + } + void testCase3(){ + stdPair temp1 = std::make_pair(std::string("zxh"), std::string("zxh")); + stdPair p1 = temp1; + + tsPair temp2 = TinySTL::make_pair(std::string("zxh"), std::string("zxh")); + tsPair p2 = temp2; + + assert(container_equal(p1, p2)); + } + void testCase4(){ + TinySTL::pair foo(10, 'z'); + TinySTL::pair bar(90, 'a'); + + //foo and bar are not equal + //foo is less than bar + //foo is less than or equal to bar + if (foo == bar) std::cout << "foo and bar are equal\n"; + if (foo != bar) std::cout << "foo and bar are not equal\n"; + if (foo< bar) std::cout << "foo is less than bar\n"; + if (foo> bar) std::cout << "foo is greater than bar\n"; + if (foo <= bar) std::cout << "foo is less than or equal to bar\n"; + if (foo >= bar) std::cout << "foo is greater than or equal to bar\n"; + } + void testCase5(){ + TinySTL::pair foo(10, 'z'); + TinySTL::pair bar(90, 'a'); + + foo.swap(bar); + + std::cout << "foo : (" << foo.first << ", " << foo.second << ")" << std::endl; + std::cout << "bar : (" << bar.first << ", " << bar.second << ")" << std::endl; + //TinySTL::Test::print_container(foo); + //TinySTL::Test::print_container(bar); + } + } +} +//using namespace TinySTL::PairTest; +//int main(){ +// testCase1(); +// testCase2(); +// testCase3(); +// testCase4(); +// testCase5(); +// system("pause"); +// return 0; +//} \ No newline at end of file diff --git a/TinySTL/Test/PairTest.h b/TinySTL/Test/PairTest.h index d990286..a150a35 100644 --- a/TinySTL/Test/PairTest.h +++ b/TinySTL/Test/PairTest.h @@ -1,10 +1,27 @@ #ifndef _PAIR_TEST_H_ #define _PAIR_TEST_H_ -void testCase1(); -void testCase2(); -void testCase3(); -void testCase4(); -void testCase5(); +#include "TestUtil.h" +#include "../Utility.h" +#include + +#include +#include +#include + +namespace TinySTL{ + namespace PairTest{ + template + using stdPair = std::pair < T, T > ; + template + using tsPair = TinySTL::pair < T, T > ; + + void testCase1(); + void testCase2(); + void testCase3(); + void testCase4(); + void testCase5(); + } +} #endif \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index a70251b..b3c6c24 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -102,6 +102,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index 82815b4..08403ec 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -101,6 +101,9 @@ Test + + Test +