|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <vector> |
|
18 #include <list> |
|
19 #include <algorithm> |
|
20 |
|
21 #include "cppunit/cppunit_proxy.h" |
|
22 |
|
23 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) |
|
24 using namespace std; |
|
25 #endif |
|
26 |
|
27 // |
|
28 // TestCase class |
|
29 // |
|
30 class ReviterTest : public CPPUNIT_NS::TestCase |
|
31 { |
|
32 CPPUNIT_TEST_SUITE(ReviterTest); |
|
33 CPPUNIT_TEST(reviter1); |
|
34 CPPUNIT_TEST(reviter2); |
|
35 CPPUNIT_TEST(revbit1); |
|
36 CPPUNIT_TEST_SUITE_END(); |
|
37 |
|
38 protected: |
|
39 void reviter1(); |
|
40 void reviter2(); |
|
41 void revbit1(); |
|
42 }; |
|
43 |
|
44 CPPUNIT_TEST_SUITE_REGISTRATION(ReviterTest); |
|
45 |
|
46 // |
|
47 // tests implementation |
|
48 // |
|
49 void ReviterTest::reviter1() |
|
50 { |
|
51 int array [] = { 1, 5, 2, 3 }; |
|
52 |
|
53 vector<int> v(array, array + 4); |
|
54 typedef vector<int>::reverse_iterator reviter; |
|
55 reviter r(v.rend()); |
|
56 r--; |
|
57 |
|
58 CPPUNIT_ASSERT(*r-- == 1); |
|
59 CPPUNIT_ASSERT(*r-- == 5); |
|
60 CPPUNIT_ASSERT(*r-- == 2); |
|
61 CPPUNIT_ASSERT(*r == 3); |
|
62 CPPUNIT_ASSERT(r==v.rbegin()); |
|
63 } |
|
64 void ReviterTest::reviter2() |
|
65 { |
|
66 int array [] = { 1, 5, 2, 3 }; |
|
67 |
|
68 vector<int> v(array, array + 4); |
|
69 vector<int>::reverse_iterator r; |
|
70 r = v.rbegin(); |
|
71 CPPUNIT_ASSERT(*r++ == 3); |
|
72 CPPUNIT_ASSERT(*r++ == 2); |
|
73 CPPUNIT_ASSERT(*r++ == 5); |
|
74 CPPUNIT_ASSERT(*r++ == 1); |
|
75 CPPUNIT_ASSERT(r==v.rend()); |
|
76 } |
|
77 void ReviterTest::revbit1() |
|
78 { |
|
79 int array [] = { 1, 5, 2, 3 }; |
|
80 |
|
81 list<int> v(array, array + 4); |
|
82 list<int>::reverse_iterator r(v.rbegin()); |
|
83 CPPUNIT_ASSERT(*r++ == 3); |
|
84 CPPUNIT_ASSERT(*r++ == 2); |
|
85 CPPUNIT_ASSERT(*r++ == 5); |
|
86 CPPUNIT_ASSERT(*r++ == 1); |
|
87 CPPUNIT_ASSERT(r==v.rend()); |
|
88 } |