添加对pair的test
This commit is contained in:
45
TinySTL/Test/PairTest.cpp
Normal file
45
TinySTL/Test/PairTest.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "..\Utility.h"
|
||||||
|
#include "..\String.h"
|
||||||
|
|
||||||
|
using namespace TinySTL;
|
||||||
|
int main(){
|
||||||
|
// test ctor
|
||||||
|
pair <string, double> product1; // default constructor
|
||||||
|
pair <string, double> product2("tomatoes", 2.30); // value init
|
||||||
|
pair <string, double> 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 <string, int> 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<int, char> foo1(10, 'a');
|
||||||
|
pair<int, char> 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<int, char> foo(10, 'z');
|
||||||
|
pair<int, char> 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;
|
||||||
|
}
|
||||||
@@ -81,6 +81,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="Profiler\Profiler.cpp" />
|
<ClCompile Include="Profiler\Profiler.cpp" />
|
||||||
|
<ClCompile Include="Test\PairTest.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Algorithm.h" />
|
<ClInclude Include="Algorithm.h" />
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
<Filter Include="头文件\Profiler">
|
<Filter Include="头文件\Profiler">
|
||||||
<UniqueIdentifier>{092c2875-2b56-404b-977e-a9b4aa67c134}</UniqueIdentifier>
|
<UniqueIdentifier>{092c2875-2b56-404b-977e-a9b4aa67c134}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Test">
|
||||||
|
<UniqueIdentifier>{102ada31-2e23-4fa3-b913-81e7e40d12a7}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
@@ -24,6 +27,9 @@
|
|||||||
<ClCompile Include="Profiler\Profiler.cpp">
|
<ClCompile Include="Profiler\Profiler.cpp">
|
||||||
<Filter>头文件\Profiler</Filter>
|
<Filter>头文件\Profiler</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Test\PairTest.cpp">
|
||||||
|
<Filter>Test</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="TypeTraits.h">
|
<ClInclude Include="TypeTraits.h">
|
||||||
|
|||||||
Reference in New Issue
Block a user