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
private
:
29
/**
30
* Run the test
31
*/
32
void
DoRun
()
override
;
33
};
34
35
void
36
SymmetricAdjacencyMatrixTestCase::DoRun
()
37
{
38
SymmetricAdjacencyMatrix<bool>
boolAdj;
39
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
40
0,
41
"Should have 0 rows, but have "
<< boolAdj.
GetRows
());
42
boolAdj.
AddRow
();
43
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
44
1,
45
"Should have 1 rows, but have "
<< boolAdj.
GetRows
());
46
boolAdj.
AddRow
();
47
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
48
2,
49
"Should have 2 rows, but have "
<< boolAdj.
GetRows
());
50
boolAdj.
AddRow
();
51
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
52
3,
53
"Should have 3 rows, but have "
<< boolAdj.
GetRows
());
54
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(0, 0),
false
,
"Should be set to false"
);
55
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 0),
false
,
"Should be set to false"
);
56
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 1),
false
,
"Should be set to false"
);
57
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 0),
false
,
"Should be set to false"
);
58
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 1),
false
,
"Should be set to false"
);
59
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 2),
false
,
"Should be set to false"
);
60
61
// Test constructor with arguments
62
boolAdj =
SymmetricAdjacencyMatrix<bool>
(3,
true
);
63
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(0, 0),
true
,
"Should be set to false"
);
64
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 0),
true
,
"Should be set to false"
);
65
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(1, 1),
true
,
"Should be set to false"
);
66
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 0),
true
,
"Should be set to false"
);
67
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 1),
true
,
"Should be set to false"
);
68
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(2, 2),
true
,
"Should be set to false"
);
69
70
// Set value setting
71
boolAdj =
SymmetricAdjacencyMatrix<bool>
(4,
false
);
72
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetRows
(),
73
4,
74
"Should have 4 rows, but have "
<< boolAdj.
GetRows
());
75
for
(
int
i = 0; i < 4; i++)
76
{
77
// Mark all adjacent values to row i to true
78
boolAdj.
SetValueAdjacent
(i,
true
);
79
for
(
int
j = 0; j < 4; j++)
80
{
81
for
(
int
k = 0; k < 4; k++)
82
{
83
// Check if adjacent values to i were marked as true
84
if
(i == j || i == k)
85
{
86
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
true
,
"Should be set to true"
);
87
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
true
,
"Should be set to true"
);
88
}
89
else
90
{
91
// Check if all other values are marked as false
92
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
false
,
"Should be set to false"
);
93
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
false
,
"Should be set to false"
);
94
}
95
}
96
}
97
// Reset values
98
for
(
int
j = 0; j < 4; j++)
99
{
100
for
(
int
k = 0; k < 4; k++)
101
{
102
if
(i == j || i == k)
103
{
104
boolAdj.
SetValue
(j, k,
false
);
105
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(j, k),
false
,
"Should be set to false"
);
106
NS_TEST_EXPECT_MSG_EQ
(boolAdj.
GetValue
(k, j),
false
,
"Should be set to false"
);
107
}
108
}
109
}
110
}
111
}
112
113
/**
114
* @ingroup core-tests
115
*
116
* @brief AdjacencyMatrix Test Suite
117
*/
118
class
AdjacencyMatrixTestSuite
:
public
TestSuite
119
{
120
public
:
121
AdjacencyMatrixTestSuite
();
122
};
123
124
AdjacencyMatrixTestSuite::AdjacencyMatrixTestSuite
()
125
:
TestSuite
(
"adjacency-matrix-test"
,
Type
::UNIT)
126
{
127
AddTestCase
(
new
SymmetricAdjacencyMatrixTestCase
(), TestCase::Duration::QUICK);
128
}
129
130
static
AdjacencyMatrixTestSuite
adjacencyMatrixTestSuiteInstance
;
AdjacencyMatrixTestSuite
AdjacencyMatrix Test Suite.
Definition
test-adjacency-matrix.cc:119
AdjacencyMatrixTestSuite::AdjacencyMatrixTestSuite
AdjacencyMatrixTestSuite()
Definition
test-adjacency-matrix.cc:124
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:36
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:130
src
antenna
test
test-adjacency-matrix.cc
Generated on Tue Apr 8 2025 15:27:10 for ns-3 by
1.11.0