31
|
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 <algorithm>
|
|
19 |
|
|
20 |
#include "cppunit/cppunit_proxy.h"
|
|
21 |
|
|
22 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
|
23 |
using namespace std;
|
|
24 |
#endif
|
|
25 |
|
|
26 |
//
|
|
27 |
// TestCase class
|
|
28 |
//
|
|
29 |
class MinTest : public CPPUNIT_NS::TestCase
|
|
30 |
{
|
|
31 |
CPPUNIT_TEST_SUITE(MinTest);
|
|
32 |
CPPUNIT_TEST(min1);
|
|
33 |
CPPUNIT_TEST(min2);
|
|
34 |
CPPUNIT_TEST(minelem1);
|
|
35 |
CPPUNIT_TEST(minelem2);
|
|
36 |
CPPUNIT_TEST_SUITE_END();
|
|
37 |
|
|
38 |
protected:
|
|
39 |
void min1();
|
|
40 |
void min2();
|
|
41 |
void minelem1();
|
|
42 |
void minelem2();
|
|
43 |
static bool str_compare(const char* a_, const char* b_)
|
|
44 |
{ return strcmp(a_, b_) < 0 ? 1 : 0; }
|
|
45 |
};
|
|
46 |
|
|
47 |
CPPUNIT_TEST_SUITE_REGISTRATION(MinTest);
|
|
48 |
|
|
49 |
//
|
|
50 |
// tests implementation
|
|
51 |
//
|
|
52 |
void MinTest::min1()
|
|
53 |
{
|
|
54 |
int r = min(42, 100);
|
|
55 |
CPPUNIT_ASSERT( r == 42 );
|
|
56 |
|
|
57 |
r = min(--r, r);
|
|
58 |
CPPUNIT_ASSERT( r == 41 );
|
|
59 |
}
|
|
60 |
void MinTest::min2()
|
|
61 |
{
|
|
62 |
const char* r = min((const char*)"shoe", (const char*)"shine", str_compare);
|
|
63 |
CPPUNIT_ASSERT(!strcmp(r, "shine"));
|
|
64 |
}
|
|
65 |
void MinTest::minelem1()
|
|
66 |
{
|
|
67 |
int numbers[6] = { -10, 15, -100, 36, -242, 42 };
|
|
68 |
int* r = min_element((int*)numbers, (int*)numbers + 6);
|
|
69 |
CPPUNIT_ASSERT(*r==-242);
|
|
70 |
}
|
|
71 |
void MinTest::minelem2()
|
|
72 |
{
|
|
73 |
const char* names[] = { "Brett", "Graham", "Jack", "Mike", "Todd" };
|
|
74 |
|
|
75 |
const unsigned namesCt = sizeof(names) / sizeof(names[0]);
|
|
76 |
const char** r = min_element((const char**)names, (const char**)names + namesCt, str_compare);
|
|
77 |
CPPUNIT_ASSERT(!strcmp(*r, "Brett"));
|
|
78 |
}
|