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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Andrea Sacco <andrea.sacco85@gmail.com>
18
*/
19
20
#include "ns3/li-ion-energy-source.h"
21
#include "ns3/log.h"
22
#include "ns3/node.h"
23
#include "ns3/simple-device-energy-model.h"
24
#include "ns3/simulator.h"
25
#include "ns3/test.h"
26
27
using namespace
ns3
;
28
using namespace
ns3::energy
;
29
30
NS_LOG_COMPONENT_DEFINE
(
"LiIonEnergySourceTestSuite"
);
31
32
/**
33
* \ingroup energy-tests
34
*
35
* \brief LiIon battery Test
36
*/
37
class
LiIonEnergyTestCase
:
public
TestCase
38
{
39
public
:
40
LiIonEnergyTestCase
();
41
~LiIonEnergyTestCase
()
override
;
42
43
void
DoRun
()
override
;
44
45
Ptr<Node>
m_node
;
//!< Node to aggreagte the source to.
46
};
47
48
LiIonEnergyTestCase::LiIonEnergyTestCase
()
49
:
TestCase
(
"Li-Ion energy source test case"
)
50
{
51
}
52
53
LiIonEnergyTestCase::~LiIonEnergyTestCase
()
54
{
55
m_node
=
nullptr
;
56
}
57
58
void
59
LiIonEnergyTestCase::DoRun
()
60
{
61
m_node
= CreateObject<Node>();
62
63
Ptr<SimpleDeviceEnergyModel>
sem = CreateObject<SimpleDeviceEnergyModel>();
64
Ptr<LiIonEnergySource>
es = CreateObject<LiIonEnergySource>();
65
66
es->SetNode(
m_node
);
67
sem->SetEnergySource(es);
68
es->AppendDeviceEnergyModel(sem);
69
m_node
->
AggregateObject
(es);
70
71
Time
now =
Simulator::Now
();
72
73
// discharge at 2.33 A for 1700 seconds
74
sem->SetCurrentA(2.33);
75
now +=
Seconds
(1701);
76
77
Simulator::Stop
(now);
78
Simulator::Run
();
79
Simulator::Destroy
();
80
81
NS_TEST_ASSERT_MSG_EQ_TOL
(es->GetSupplyVoltage(), 3.6, 1.0e-3,
"Incorrect consumed energy!"
);
82
}
83
84
/**
85
* \ingroup energy-tests
86
*
87
* \brief LiIon battery TestSuite
88
*/
89
class
LiIonEnergySourceTestSuite
:
public
TestSuite
90
{
91
public
:
92
LiIonEnergySourceTestSuite
();
93
};
94
95
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
()
96
:
TestSuite
(
"li-ion-energy-source"
,
Type
::UNIT)
97
{
98
AddTestCase
(
new
LiIonEnergyTestCase
, TestCase::Duration::QUICK);
99
}
100
101
/// create an instance of the test suite
102
static
LiIonEnergySourceTestSuite
g_liIonEnergySourceTestSuite
;
LiIonEnergySourceTestSuite
LiIon battery TestSuite.
Definition:
li-ion-energy-source-test.cc:90
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
LiIonEnergySourceTestSuite()
Definition:
li-ion-energy-source-test.cc:95
LiIonEnergyTestCase
LiIon battery Test.
Definition:
li-ion-energy-source-test.cc:38
LiIonEnergyTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
li-ion-energy-source-test.cc:59
LiIonEnergyTestCase::LiIonEnergyTestCase
LiIonEnergyTestCase()
Definition:
li-ion-energy-source-test.cc:48
LiIonEnergyTestCase::m_node
Ptr< Node > m_node
Node to aggreagte the source to.
Definition:
li-ion-energy-source-test.cc:45
LiIonEnergyTestCase::~LiIonEnergyTestCase
~LiIonEnergyTestCase() override
Definition:
li-ion-energy-source-test.cc:53
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition:
object.cc:309
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:208
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:186
ns3::TestCase
encapsulates test code
Definition:
test.h:1061
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:302
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1273
ns3::TestSuite::Type
Type
Type of test.
Definition:
test.h:1280
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:338
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1319
g_liIonEnergySourceTestSuite
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Definition:
li-ion-energy-source-test.cc:102
ns3::energy
Definition:
energy-harvester-container.cc:29
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 May 28 2024 23:35:20 for ns-3 by
1.9.6