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
li-ion-energy-source-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Andrea Sacco
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Andrea Sacco <andrea.sacco85@gmail.com>
7
*/
8
9
#include "ns3/li-ion-energy-source.h"
10
#include "ns3/log.h"
11
#include "ns3/node.h"
12
#include "ns3/simple-device-energy-model.h"
13
#include "ns3/simulator.h"
14
#include "ns3/test.h"
15
16
using namespace
ns3
;
17
using namespace
ns3::energy
;
18
19
// NS_DEPRECATED_3_43() - tag for future removal
20
// LiIonEnergySource was deprecated in commit
21
// https://gitlab.com/nsnam/ns-3-dev/-/commit/086913b0
22
//
23
// The new battery model is illustrated in
24
// `src/energy/examples/generic-battery-discharge-example.cc`
25
//
26
// A GenericBatteryModelTestCase is being developed in MR 2181
27
// https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/2181
28
// which will be in
29
// `src/energy/test/generic-battery-model-test.cc`
30
31
NS_LOG_COMPONENT_DEFINE
(
"LiIonEnergySourceTestSuite"
);
32
33
/**
34
* @ingroup energy-tests
35
*
36
* @brief LiIon battery Test
37
*/
38
class
LiIonEnergyTestCase
:
public
TestCase
39
{
40
public
:
41
LiIonEnergyTestCase
();
42
~LiIonEnergyTestCase
()
override
;
43
44
void
DoRun
()
override
;
45
46
Ptr<Node>
m_node
;
//!< Node to aggreagte the source to.
47
};
48
49
LiIonEnergyTestCase::LiIonEnergyTestCase
()
50
:
TestCase
(
"Li-Ion energy source test case"
)
51
{
52
}
53
54
LiIonEnergyTestCase::~LiIonEnergyTestCase
()
55
{
56
m_node
=
nullptr
;
57
}
58
59
void
60
LiIonEnergyTestCase::DoRun
()
61
{
62
m_node
=
CreateObject<Node>
();
63
64
Ptr<SimpleDeviceEnergyModel>
sem =
CreateObject<SimpleDeviceEnergyModel>
();
65
66
NS_WARNING_PUSH_DEPRECATED
;
67
Ptr<LiIonEnergySource>
es =
CreateObject<LiIonEnergySource>
();
68
NS_WARNING_POP
;
69
70
es->SetNode(
m_node
);
71
sem->SetEnergySource(es);
72
es->AppendDeviceEnergyModel(sem);
73
m_node
->
AggregateObject
(es);
74
75
Time
now =
Simulator::Now
();
76
77
// discharge at 2.33 A for 1700 seconds
78
sem->SetCurrentA(2.33);
79
now +=
Seconds
(1701);
80
81
Simulator::Stop
(now);
82
Simulator::Run
();
83
Simulator::Destroy
();
84
85
NS_TEST_ASSERT_MSG_EQ_TOL
(es->GetSupplyVoltage(), 3.6, 1.0e-3,
"Incorrect consumed energy!"
);
86
}
87
88
/**
89
* @ingroup energy-tests
90
*
91
* @brief LiIon battery TestSuite
92
*/
93
class
LiIonEnergySourceTestSuite
:
public
TestSuite
94
{
95
public
:
96
LiIonEnergySourceTestSuite
();
97
};
98
99
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
()
100
:
TestSuite
(
"li-ion-energy-source"
,
Type
::UNIT)
101
{
102
AddTestCase
(
new
LiIonEnergyTestCase
, TestCase::Duration::QUICK);
103
}
104
105
/// create an instance of the test suite
106
static
LiIonEnergySourceTestSuite
g_liIonEnergySourceTestSuite
;
LiIonEnergySourceTestSuite
LiIon battery TestSuite.
Definition
li-ion-energy-source-test.cc:94
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
LiIonEnergySourceTestSuite()
Definition
li-ion-energy-source-test.cc:99
LiIonEnergyTestCase
LiIon battery Test.
Definition
li-ion-energy-source-test.cc:39
LiIonEnergyTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
li-ion-energy-source-test.cc:60
LiIonEnergyTestCase::LiIonEnergyTestCase
LiIonEnergyTestCase()
Definition
li-ion-energy-source-test.cc:49
LiIonEnergyTestCase::m_node
Ptr< Node > m_node
Node to aggreagte the source to.
Definition
li-ion-energy-source-test.cc:46
LiIonEnergyTestCase::~LiIonEnergyTestCase
~LiIonEnergyTestCase() override
Definition
li-ion-energy-source-test.cc:54
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition
object.cc:298
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
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
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
NS_TEST_ASSERT_MSG_EQ_TOL
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition
test.h:327
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
NS_WARNING_POP
#define NS_WARNING_POP
Pops the diagnostic warning list from the stack, restoring it to the previous state.
Definition
warnings.h:102
NS_WARNING_PUSH_DEPRECATED
#define NS_WARNING_PUSH_DEPRECATED
Save the current warning list and disables the ones about deprecated functions and classes.
Definition
warnings.h:114
g_liIonEnergySourceTestSuite
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Definition
li-ion-energy-source-test.cc:106
ns3::energy
Definition
energy-harvester-container.cc:18
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
energy
test
li-ion-energy-source-test.cc
Generated on Tue Dec 10 2024 18:20:39 for ns-3 by
1.11.0