A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
test-adjacency-matrix.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 CTTC
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
7
*/
8
9
#include "ns3/symmetric-adjacency-matrix.h"
10
#include "ns3/test.h"
11
12
using namespace
ns3
;
13
14
/**
15
* @ingroup antenna-tests
16
*
17
* @brief SymmetricAdjacencyMatrix Test Case
18
*/
19
class
SymmetricAdjacencyMatrixTestCase
:
public
TestCase
20
{
21
public
:
22
/**
23
* The constructor of the test case
24
*/
25
SymmetricAdjacencyMatrixTestCase
()
26
:
TestCase
(
"SymmetricAdjacencyMatrix test case"
)
27
{
28
}
29
30
private
:
31
/**
32
* Run the test
33
*/
34
void
DoRun
()
override
;
35
};
36
37
void
38
SymmetricAdjacencyMatrixTestCase::DoRun
()
39
{
40
SymmetricAdjacencyMatrix<bool>
boolAdj;
41
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
42
0,
43
"Should have 0 rows, but have "
<< boolAdj.
GetRows
());
44
boolAdj.
AddRow
();
45
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
46
1,
47
"Should have 1 rows, but have "
<< boolAdj.
GetRows
());
48
boolAdj.
AddRow
();
49
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
50
2,
51
"Should have 2 rows, but have "
<< boolAdj.
GetRows
());
52
boolAdj.
AddRow
();
53
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
54
3,
55
"Should have 3 rows, but have "
<< boolAdj.
GetRows
());
56
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(0, 0),
false
,
"Should be set to false"
);
57
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 0),
false
,
"Should be set to false"
);
58
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 1),
false
,
"Should be set to false"
);
59
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 0),
false
,
"Should be set to false"
);
60
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 1),
false
,
"Should be set to false"
);
61
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 2),
false
,
"Should be set to false"
);
62
63
// Test constructor with arguments
64
boolAdj =
SymmetricAdjacencyMatrix<bool>
(3,
true
);
65
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(0, 0),
true
,
"Should be set to false"
);
66
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 0),
true
,
"Should be set to false"
);
67
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 1),
true
,
"Should be set to false"
);
68
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 0),
true
,
"Should be set to false"
);
69
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 1),
true
,
"Should be set to false"
);
70
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 2),
true
,
"Should be set to false"
);
71
72
// Set value setting
73
boolAdj =
SymmetricAdjacencyMatrix<bool>
(4,
false
);
74
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
75
4,
76
"Should have 4 rows, but have "
<< boolAdj.
GetRows
());
77
for
(
int
i = 0; i < 4; i++)
78
{
79
// Mark all adjacent values to row i to true
80
boolAdj.
SetValueAdjacent
(i,
true
);
81
for
(
int
j = 0; j < 4; j++)
82
{
83
for
(
int
k = 0; k < 4; k++)
84
{
85
// Check if adjacent values to i were marked as true
86
if
(i == j || i == k)
87
{
88
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
true
,
"Should be set to true"
);
89
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
true
,
"Should be set to true"
);
90
}
91
else
92
{
93
// Check if all other values are marked as false
94
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
false
,
"Should be set to false"
);
95
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
false
,
"Should be set to false"
);
96
}
97
}
98
}
99
// Reset values
100
for
(
int
j = 0; j < 4; j++)
101
{
102
for
(
int
k = 0; k < 4; k++)
103
{
104
if
(i == j || i == k)
105
{
106
boolAdj.
SetValue
(j, k,
false
);
107
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
false
,
"Should be set to false"
);
108
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
false
,
"Should be set to false"
);
109
}
110
}
111
}
112
}
113
}
114
115
/**
116
* @ingroup core-tests
117
*
118
* @brief AdjacencyMatrix Test Suite
119
*/
120
class
AdjacencyMatrixTestSuite
:
public
TestSuite
121
{
122
public
:
123
AdjacencyMatrixTestSuite
();
124
};
125
126
AdjacencyMatrixTestSuite::AdjacencyMatrixTestSuite
()
127
:
TestSuite
(
"adjacency-matrix-test"
,
Type
::UNIT)
128
{
129
AddTestCase
(
new
SymmetricAdjacencyMatrixTestCase
(), TestCase::Duration::QUICK);
130
}
131
132
static
AdjacencyMatrixTestSuite
adjacencyMatrixTestSuiteInstance
;
AdjacencyMatrixTestSuite
AdjacencyMatrix Test Suite.
Definition
test-adjacency-matrix.cc:121
AdjacencyMatrixTestSuite::AdjacencyMatrixTestSuite
AdjacencyMatrixTestSuite()
Definition
test-adjacency-matrix.cc:126
SymmetricAdjacencyMatrixTestCase
SymmetricAdjacencyMatrix Test Case.
Definition
test-adjacency-matrix.cc:20
SymmetricAdjacencyMatrixTestCase::SymmetricAdjacencyMatrixTestCase
SymmetricAdjacencyMatrixTestCase()
The constructor of the test case.
Definition
test-adjacency-matrix.cc:25
SymmetricAdjacencyMatrixTestCase::DoRun
void DoRun() override
Run the test.
Definition
test-adjacency-matrix.cc:38
ns3::SymmetricAdjacencyMatrix
A class representing a symmetric adjacency matrix.
Definition
symmetric-adjacency-matrix.h:233
ns3::SymmetricAdjacencyMatrix::GetValue
T GetValue(size_t row, size_t column)
Retrieve the value of matrix (row, column) node.
Definition
symmetric-adjacency-matrix.h:257
ns3::SymmetricAdjacencyMatrix::SetValueAdjacent
void SetValueAdjacent(size_t row, T value)
Set the value of adjacent nodes of a given node (all columns of a given row, and its reflection)
Definition
symmetric-adjacency-matrix.h:285
ns3::SymmetricAdjacencyMatrix::GetRows
size_t GetRows()
Retrieve number of rows in the adjacency matrix.
Definition
symmetric-adjacency-matrix.h:316
ns3::SymmetricAdjacencyMatrix::AddRow
void AddRow()
Add new row to the adjacency matrix.
Definition
symmetric-adjacency-matrix.h:305
ns3::SymmetricAdjacencyMatrix::SetValue
void SetValue(size_t row, size_t column, T value)
Set the value of matrix (row, column) node.
Definition
symmetric-adjacency-matrix.h:271
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition
test.h:241
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
adjacencyMatrixTestSuiteInstance
static AdjacencyMatrixTestSuite adjacencyMatrixTestSuiteInstance
Definition
test-adjacency-matrix.cc:132
src
antenna
test
test-adjacency-matrix.cc
Generated on Tue Apr 29 2025 11:06:50 for ns-3 by
1.11.0