Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 453334af26c5b30d66c447c9eaabd6dfd8cd94ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 *
 *******************************************************************************/

#include "PairTest.h"

#include "common/containers/Pair.h"
#include "common/containers/String.h"
#include "util/etAssert.h"

using namespace etRuntime;

void PairTest::testConstructors(void) {
	Pair<int, int> p1;
	EXPECT_EQUAL_INT32(m_caseId, "p1.first", 0, p1.first);
	EXPECT_EQUAL_INT32(m_caseId, "p1.second", 0, p1.second);

	Pair<int, int> p2(1, 2);
	EXPECT_EQUAL_INT32(m_caseId, "p1.first", 1, p2.first);
	EXPECT_EQUAL_INT32(m_caseId, "p1.second", 2, p2.second);

	Pair<int, String> p3;
	EXPECT_EQUAL_INT32(m_caseId, "p1.first", 0, p3.first);
	EXPECT_TRUE(m_caseId, "p1.second", p3.second=="");

	Pair<int, String> p4(123, "pair");
	EXPECT_EQUAL_INT32(m_caseId, "p1.first", 123, p4.first);
	EXPECT_TRUE(m_caseId, "p1.second", p4.second=="pair");
}

void PairTest::testOperators(void) {
	Pair<int, int> p1(2,2), p2(1, 1);
	EXPECT_TRUE(m_caseId, "p1>p2", p1>p2);
	EXPECT_TRUE(m_caseId, "!p1<p2", !(p1<p2));
	EXPECT_TRUE(m_caseId, "p1!=p2", p1!=p2);

	p1.first = 1;
	EXPECT_TRUE(m_caseId, "p1>p2", p1>p2);
	EXPECT_TRUE(m_caseId, "!p1<p2", !(p1<p2));
	EXPECT_TRUE(m_caseId, "p1!=p2", p1!=p2);

	p1.second = 1;
	EXPECT_TRUE(m_caseId, "!p1>p2", !(p1>p2));
	EXPECT_TRUE(m_caseId, "!p1<p2", !(p1<p2));
	EXPECT_TRUE(m_caseId, "p1>=p2", p1>=p2);
	EXPECT_TRUE(m_caseId, "p1<=p2", p1<=p2);
	EXPECT_TRUE(m_caseId, "p1==p2", p1==p2);
}

void PairTest::runAllTestCases() {
	ADD_TESTCASE_CPP(testConstructors)
	ADD_TESTCASE_CPP(testOperators)
}

Back to the top