31
|
1 |
|
|
2 |
// STLport regression testsuite component.
|
|
3 |
// To compile as a separate example, please #define MAIN.
|
|
4 |
|
|
5 |
#include <iostream>
|
|
6 |
#include <map>
|
|
7 |
|
|
8 |
#ifdef MAIN
|
|
9 |
#define map1_test main
|
|
10 |
#endif
|
|
11 |
|
|
12 |
#if !defined (STLPORT) || defined(__STL_USE_NAMESPACES)
|
|
13 |
using namespace std;
|
|
14 |
#endif
|
|
15 |
|
|
16 |
#include "map1.hpp"
|
|
17 |
ostream& operator<<(ostream& s, Int x)
|
|
18 |
{ return s << x.val; }
|
|
19 |
|
|
20 |
int map1_test(int, char**)
|
|
21 |
{
|
|
22 |
cout<<"Results of map1_test:"<<endl;
|
|
23 |
typedef map<char, Int, less<char> > maptype;
|
|
24 |
maptype m;
|
|
25 |
int failures = 0;
|
|
26 |
// Store mappings between roman numerals and decimals.
|
|
27 |
char ch = 'l';
|
|
28 |
m[ch] = 50;
|
|
29 |
m['x'] = 20; // Deliberate mistake.
|
|
30 |
m['v'] = 5;
|
|
31 |
m['i'] = 1;
|
|
32 |
cout << "m['x'] = " << m['x'] << endl;
|
|
33 |
m['x'] = 10; // Correct mistake.
|
|
34 |
cout << "m['x'] = " << m['x'] << endl;
|
|
35 |
cout << "m['z'] = " << m['z'] << endl; // Note default value is added.
|
|
36 |
cout << "m.count('z') = " << m.count('z') << endl;
|
|
37 |
|
|
38 |
pair<maptype::iterator, bool> p =
|
|
39 |
m.insert(pair<const char, Int>('c', 100));
|
|
40 |
if(p.second)
|
|
41 |
cout << "First insertion successful" << endl;
|
|
42 |
p = m.insert(pair<const char, Int>('c', 100));
|
|
43 |
if(p.second)
|
|
44 |
{
|
|
45 |
|
|
46 |
cout << "Second insertion successful" << endl;
|
|
47 |
failures++;
|
|
48 |
}
|
|
49 |
else
|
|
50 |
cout << "Existing pair " <<(*(p.first)).first
|
|
51 |
<< " -> " <<(*(p.first)).second << endl;
|
|
52 |
Int a = 100;
|
|
53 |
if(((*(p.first)).first) != 'c')
|
|
54 |
failures++;
|
|
55 |
if ((*(p.first)).second != a)
|
|
56 |
failures++;
|
|
57 |
return failures;
|
|
58 |
}
|