diff --git a/TinySTL/Test/PairTest.cpp b/TinySTL/Test/PairTest.cpp new file mode 100644 index 0000000..c8eb905 --- /dev/null +++ b/TinySTL/Test/PairTest.cpp @@ -0,0 +1,45 @@ +#include + +#include "..\Utility.h" +#include "..\String.h" + +using namespace TinySTL; +int main(){ + // 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"; + system("pause"); + return 0; +} \ No newline at end of file diff --git a/TinySTL/TinySTL.vcxproj b/TinySTL/TinySTL.vcxproj index fd62738..e780ece 100644 --- a/TinySTL/TinySTL.vcxproj +++ b/TinySTL/TinySTL.vcxproj @@ -81,6 +81,7 @@ + diff --git a/TinySTL/TinySTL.vcxproj.filters b/TinySTL/TinySTL.vcxproj.filters index 57f3834..2a2a082 100644 --- a/TinySTL/TinySTL.vcxproj.filters +++ b/TinySTL/TinySTL.vcxproj.filters @@ -16,6 +16,9 @@ {092c2875-2b56-404b-977e-a9b4aa67c134} + + {102ada31-2e23-4fa3-b913-81e7e40d12a7} + @@ -24,6 +27,9 @@ 头文件\Profiler + + Test +