From 721dca3e39584f9fd7b75621a8f82942eb88aae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 5 Nov 2014 10:02:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9pair=E7=9A=84test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Test/PairTest.cpp | 45 +++++++++++++++++++++++++++++++++ TinySTL/TinySTL.vcxproj | 1 + TinySTL/TinySTL.vcxproj.filters | 6 +++++ 3 files changed, 52 insertions(+) create mode 100644 TinySTL/Test/PairTest.cpp 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 +