|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
3 |
* Copyright (c) 2009 University of Applied Sciences Rapperswil, Switzerland (HSR) |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License version 2 as |
7 |
* published by the Free Software Foundation; |
8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
* GNU General Public License for more details. |
13 |
* |
14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 |
* |
18 |
* Author: Fabian Mauchle <fabian.mauchle@hsr.ch> |
19 |
*/ |
20 |
|
21 |
#include "sequence.h" |
22 |
#include "ns3/test.h" |
23 |
|
24 |
//all functions are implemented in the header |
25 |
|
26 |
//--sequence test |
27 |
|
28 |
namespace ns3 |
29 |
{ |
30 |
|
31 |
class SequenceTest : public TestCase |
32 |
{ |
33 |
public: |
34 |
SequenceTest () : TestCase ("Check sequence mathematical correctness"){} |
35 |
virtual bool DoRun (void) |
36 |
{ |
37 |
sequence32_t testValues[][2] = { |
38 |
{1,2}, |
39 |
{-1,0}, |
40 |
{0,0xefffffff}, |
41 |
{0xefffffff,-1}, |
42 |
{0xf0000000,0}, |
43 |
{1,0xf0000000} |
44 |
}; |
45 |
|
46 |
for(int i = 0; i < 2; i++) |
47 |
{ |
48 |
sequence32_t a = testValues[i][0], |
49 |
b = testValues[i][1]; |
50 |
|
51 |
NS_TEST_EXPECT_MSG_EQ((bool)(a < b), true, "a < b"); |
52 |
|
53 |
NS_TEST_EXPECT_MSG_EQ((bool)(a > b), (bool)(b < a), "(a > b)=(b < a)"); |
54 |
NS_TEST_EXPECT_MSG_EQ((bool)(a < b), (bool)(b > a), "(a < b)=(b > a)"); |
55 |
NS_TEST_EXPECT_MSG_EQ((bool)(a <= b), (bool)(b >= a), "(a <= b)=(b >= a)"); |
56 |
NS_TEST_EXPECT_MSG_EQ((bool)(a >= b), (bool)(b <= a), "(a >= b)=(b <= a)"); |
57 |
NS_TEST_EXPECT_MSG_NE((bool)(a >= b), (bool)(a < b), "(a >= b)=(a < b)"); |
58 |
NS_TEST_EXPECT_MSG_NE((bool)(a <= b), (bool)(a > b), "(a <= b)=(a > b)"); |
59 |
} |
60 |
|
61 |
sequence32_t x = 10, y = 10; |
62 |
NS_TEST_EXPECT_MSG_EQ((bool)(x <= y), true, "x <= y"); |
63 |
NS_TEST_EXPECT_MSG_EQ((bool)(x >= y), true, "x <= y"); |
64 |
NS_TEST_EXPECT_MSG_EQ((bool)(x == y), true, "x <= y"); |
65 |
|
66 |
{ |
67 |
sequence32_t num1 (3), num2 (5); |
68 |
uint32_t value; |
69 |
|
70 |
value = num1 + num2; |
71 |
NS_TEST_EXPECT_MSG_EQ (value, 8, "num1 + num2"); |
72 |
|
73 |
num1 += num2; |
74 |
NS_TEST_EXPECT_MSG_EQ (num1, 8, "num1 += num2"); |
75 |
|
76 |
++num1; |
77 |
NS_TEST_EXPECT_MSG_EQ (num1, 9, "++num1"); |
78 |
|
79 |
--num1; |
80 |
NS_TEST_EXPECT_MSG_EQ (num1, 8, "--num1"); |
81 |
|
82 |
num1++; |
83 |
NS_TEST_EXPECT_MSG_EQ (num1, 9, "num1++"); |
84 |
|
85 |
num1--; |
86 |
NS_TEST_EXPECT_MSG_EQ (num1, 8, "num1--"); |
87 |
} |
88 |
|
89 |
{ |
90 |
NS_TEST_EXPECT_MSG_EQ ((sequence16_t (1000) + sequence16_t (6000)) - sequence16_t (1000), 6000, "(1000 + 6000) - 1000"); |
91 |
NS_TEST_EXPECT_MSG_EQ ((sequence16_t (60000) + sequence16_t (6000)) - sequence16_t (60000), 6000, "(60000 + 6000) - 60000"); |
92 |
NS_TEST_EXPECT_MSG_EQ (Sequence<int16_t> (1000) - Sequence<int16_t> (6000), -5000, "(1000 - 6000)"); |
93 |
NS_TEST_EXPECT_MSG_EQ ((Sequence<int16_t> (60000) + Sequence<int16_t> (1000)) - Sequence<int16_t> (65000), -4000, "(60000 + 1000) - 65000"); |
94 |
} |
95 |
|
96 |
{ |
97 |
sequence32_t num1 (3); |
98 |
|
99 |
NS_TEST_EXPECT_MSG_EQ (num1 + 10, 13, "num1 + 10"); |
100 |
num1 += -1; |
101 |
NS_TEST_EXPECT_MSG_EQ (num1, 2, "num1 += -1"); |
102 |
|
103 |
NS_TEST_EXPECT_MSG_EQ (num1 - (num1 - 100), 100, "num1 - (num1 - 100)"); |
104 |
} |
105 |
|
106 |
return GetErrorStatus (); |
107 |
} |
108 |
}; |
109 |
|
110 |
|
111 |
|
112 |
class SequenceTestSuite : public TestSuite |
113 |
{ |
114 |
public: |
115 |
SequenceTestSuite () : TestSuite ("sequence-test", BVT) |
116 |
{ |
117 |
AddTestCase (new SequenceTest); |
118 |
} |
119 |
} sequenceTestSuite; |
120 |
|
121 |
} |
122 |
|