A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
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
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Andrea Sacco
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Andrea Sacco <andrea.sacco85@gmail.com>
19
*/
20
21
#include "ns3/log.h"
22
#include "ns3/test.h"
23
#include "ns3/simple-device-energy-model.h"
24
#include "ns3/li-ion-energy-source.h"
25
#include "ns3/node.h"
26
#include "ns3/simulator.h"
27
28
using namespace
ns3
;
29
30
NS_LOG_COMPONENT_DEFINE
(
"LiIonEnergySourceTestSuite"
);
31
32
38
class
LiIonEnergyTestCase
:
public
TestCase
39
{
40
public
:
41
LiIonEnergyTestCase
();
42
~
LiIonEnergyTestCase
();
43
44
void
DoRun (
void
);
45
46
Ptr<Node>
m_node
;
47
};
48
49
LiIonEnergyTestCase::LiIonEnergyTestCase
()
50
:
TestCase
(
"Li-Ion energy source test case"
)
51
{
52
}
53
54
LiIonEnergyTestCase::~LiIonEnergyTestCase
()
55
{
56
m_node
= 0;
57
}
58
59
void
60
LiIonEnergyTestCase::DoRun
()
61
{
62
m_node
= CreateObject<Node> ();
63
64
Ptr<SimpleDeviceEnergyModel>
sem = CreateObject<SimpleDeviceEnergyModel> ();
65
Ptr<LiIonEnergySource>
es = CreateObject<LiIonEnergySource> ();
66
67
es->SetNode (
m_node
);
68
sem->
SetEnergySource
(es);
69
es->AppendDeviceEnergyModel (sem);
70
m_node
->
AggregateObject
(es);
71
72
Time
now =
Simulator::Now
();
73
74
// discharge at 2.33 A for 1700 seconds
75
sem->
SetCurrentA
(2.33);
76
now +=
Seconds
(1701);
77
78
Simulator::Stop (now);
79
Simulator::Run ();
80
Simulator::Destroy ();
81
82
NS_TEST_ASSERT_MSG_EQ_TOL
(es->GetSupplyVoltage (), 3.6, 1.0e-3,
83
"Incorrect consumed energy!"
);
84
}
85
91
class
LiIonEnergySourceTestSuite
:
public
TestSuite
92
{
93
public
:
94
LiIonEnergySourceTestSuite
();
95
};
96
97
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
()
98
:
TestSuite
(
"li-ion-energy-source"
, UNIT)
99
{
100
AddTestCase
(
new
LiIonEnergyTestCase
, TestCase::QUICK);
101
}
102
104
static
LiIonEnergySourceTestSuite
g_liIonEnergySourceTestSuite
;
LiIonEnergySourceTestSuite
LiIon battery TestSuite.
Definition:
li-ion-energy-source-test.cc:92
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
LiIonEnergySourceTestSuite()
Definition:
li-ion-energy-source-test.cc:97
LiIonEnergyTestCase
LiIon battery Test.
Definition:
li-ion-energy-source-test.cc:39
LiIonEnergyTestCase::~LiIonEnergyTestCase
~LiIonEnergyTestCase()
Definition:
li-ion-energy-source-test.cc:54
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::DoRun
void DoRun(void)
Implementation to actually run this TestCase.
Definition:
li-ion-energy-source-test.cc:60
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition:
object.cc:252
ns3::Ptr< Node >
ns3::SimpleDeviceEnergyModel::SetCurrentA
void SetCurrentA(double current)
Definition:
simple-device-energy-model.cc:100
ns3::SimpleDeviceEnergyModel::SetEnergySource
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
Definition:
simple-device-energy-model.cc:62
ns3::TestCase
encapsulates test code
Definition:
test.h:994
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1188
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:103
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:205
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition:
simulator.cc:287
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:323
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1244
g_liIonEnergySourceTestSuite
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Definition:
li-ion-energy-source-test.cc:104
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 Feb 6 2024 19:21:18 for ns-3 by
1.9.1