A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
29
NS_LOG_COMPONENT_DEFINE
(
"LiIonEnergySourceTestSuite"
);
30
36
class
LiIonEnergyTestCase
:
public
TestCase
37
{
38
public
:
39
LiIonEnergyTestCase
();
40
~
LiIonEnergyTestCase
()
override
;
41
42
void
DoRun()
override
;
43
44
Ptr<Node>
m_node
;
45
};
46
47
LiIonEnergyTestCase::LiIonEnergyTestCase
()
48
:
TestCase
(
"Li-Ion energy source test case"
)
49
{
50
}
51
52
LiIonEnergyTestCase::~LiIonEnergyTestCase
()
53
{
54
m_node
=
nullptr
;
55
}
56
57
void
58
LiIonEnergyTestCase::DoRun
()
59
{
60
m_node
= CreateObject<Node>();
61
62
Ptr<SimpleDeviceEnergyModel>
sem = CreateObject<SimpleDeviceEnergyModel>();
63
Ptr<LiIonEnergySource>
es = CreateObject<LiIonEnergySource>();
64
65
es->SetNode(
m_node
);
66
sem->
SetEnergySource
(es);
67
es->AppendDeviceEnergyModel(sem);
68
m_node
->
AggregateObject
(es);
69
70
Time
now =
Simulator::Now
();
71
72
// discharge at 2.33 A for 1700 seconds
73
sem->
SetCurrentA
(2.33);
74
now +=
Seconds
(1701);
75
76
Simulator::Stop(now);
77
Simulator::Run();
78
Simulator::Destroy();
79
80
NS_TEST_ASSERT_MSG_EQ_TOL
(es->GetSupplyVoltage(), 3.6, 1.0e-3,
"Incorrect consumed energy!"
);
81
}
82
88
class
LiIonEnergySourceTestSuite
:
public
TestSuite
89
{
90
public
:
91
LiIonEnergySourceTestSuite
();
92
};
93
94
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
()
95
:
TestSuite
(
"li-ion-energy-source"
, UNIT)
96
{
97
AddTestCase
(
new
LiIonEnergyTestCase
, TestCase::QUICK);
98
}
99
101
static
LiIonEnergySourceTestSuite
g_liIonEnergySourceTestSuite
;
LiIonEnergySourceTestSuite
LiIon battery TestSuite.
Definition:
li-ion-energy-source-test.cc:89
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
LiIonEnergySourceTestSuite()
Definition:
li-ion-energy-source-test.cc:94
LiIonEnergyTestCase
LiIon battery Test.
Definition:
li-ion-energy-source-test.cc:37
LiIonEnergyTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
li-ion-energy-source-test.cc:58
LiIonEnergyTestCase::LiIonEnergyTestCase
LiIonEnergyTestCase()
Definition:
li-ion-energy-source-test.cc:47
LiIonEnergyTestCase::m_node
Ptr< Node > m_node
Node to aggreagte the source to.
Definition:
li-ion-energy-source-test.cc:44
LiIonEnergyTestCase::~LiIonEnergyTestCase
~LiIonEnergyTestCase() override
Definition:
li-ion-energy-source-test.cc:52
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition:
object.cc:259
ns3::Ptr< Node >
ns3::SimpleDeviceEnergyModel::SetCurrentA
void SetCurrentA(double current)
Definition:
simple-device-energy-model.cc:102
ns3::SimpleDeviceEnergyModel::SetEnergySource
void SetEnergySource(Ptr< EnergySource > source) override
Sets pointer to EnergySource installed on node.
Definition:
simple-device-energy-model.cc:64
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
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
ns3::Now
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition:
simulator.cc:305
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:337
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
g_liIonEnergySourceTestSuite
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Definition:
li-ion-energy-source-test.cc:101
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 Sun Mar 3 2024 17:10:57 for ns-3 by
1.9.1