A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
namespace
ns3 {
29
30
NS_LOG_COMPONENT_DEFINE
(
"LiIonEnergySourceTestSuite"
)
31
;
32
33
class
LiIonEnergyTestCase
:
public
TestCase
34
{
35
public
:
36
LiIonEnergyTestCase
();
37
~LiIonEnergyTestCase
();
38
39
void
DoRun
(
void
);
40
41
double
m_simTime
;
42
Ptr<Node>
m_node
;
43
};
44
45
LiIonEnergyTestCase::LiIonEnergyTestCase
()
46
:
TestCase
(
"Li-Ion energy source test case"
)
47
{
48
}
49
50
LiIonEnergyTestCase::~LiIonEnergyTestCase
()
51
{
52
m_node
= 0;
53
}
54
55
void
56
LiIonEnergyTestCase::DoRun
()
57
{
58
m_node
= CreateObject<Node> ();
59
60
Ptr<SimpleDeviceEnergyModel>
sem = CreateObject<SimpleDeviceEnergyModel> ();
61
Ptr<LiIonEnergySource>
es = CreateObject<LiIonEnergySource> ();
62
63
es->SetNode (
m_node
);
64
sem->SetEnergySource (es);
65
es->AppendDeviceEnergyModel (sem);
66
m_node
->
AggregateObject
(es);
67
68
Time
now =
Simulator::Now
();
69
70
// discharge at 2.33 A for 1700 seconds
71
sem->SetCurrentA (2.33);
72
now += Seconds (1701);
73
74
Simulator::Stop
(now);
75
Simulator::Run
();
76
Simulator::Destroy
();
77
78
NS_TEST_ASSERT_MSG_EQ_TOL
(es->GetSupplyVoltage (), 3.6, 1.0e-3,
79
"Incorrect consumed energy!"
);
80
}
81
82
class
LiIonEnergySourceTestSuite
:
public
TestSuite
83
{
84
public
:
85
LiIonEnergySourceTestSuite
();
86
};
87
88
LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
()
89
:
TestSuite
(
"li-ion-energy-source"
, UNIT)
90
{
91
AddTestCase
(
new
LiIonEnergyTestCase
,
TestCase::QUICK
);
92
}
93
94
// create an instance of the test suite
95
static
LiIonEnergySourceTestSuite
g_liIonEnergySourceTestSuite
;
96
97
}
// namespace ns3
ns3::Time
keep track of time values and allow control of global simulation resolution
Definition:
nstime.h:81
ns3::LiIonEnergyTestCase::~LiIonEnergyTestCase
~LiIonEnergyTestCase()
Definition:
li-ion-energy-source-test.cc:50
ns3::Ptr< Node >
ns3::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
ns3::g_liIonEnergySourceTestSuite
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
Definition:
li-ion-energy-source-test.cc:95
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:326
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::Simulator::Run
static void Run(void)
Run the simulation until one of:
Definition:
simulator.cc:157
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ns3::Object::AggregateObject
void AggregateObject(Ptr< Object > other)
Definition:
object.cc:243
ns3::Simulator::Destroy
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition:
simulator.cc:121
ns3::LiIonEnergyTestCase::DoRun
void DoRun(void)
Implementation to actually run this TestCase.
Definition:
li-ion-energy-source-test.cc:56
ns3::LiIonEnergyTestCase::m_node
Ptr< Node > m_node
Definition:
li-ion-energy-source-test.cc:42
ns3::LiIonEnergySourceTestSuite
Definition:
li-ion-energy-source-test.cc:82
ns3::Simulator::Now
static Time Now(void)
Return the "current simulation time".
Definition:
simulator.cc:180
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::TestCase::QUICK
Fast test.
Definition:
test.h:857
ns3::LiIonEnergySourceTestSuite::LiIonEnergySourceTestSuite
LiIonEnergySourceTestSuite()
Definition:
li-ion-energy-source-test.cc:88
ns3::LiIonEnergyTestCase::m_simTime
double m_simTime
Definition:
li-ion-energy-source-test.cc:41
ns3::Simulator::Stop
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition:
simulator.cc:165
ns3::LiIonEnergyTestCase
Definition:
li-ion-energy-source-test.cc:33
ns3::LiIonEnergyTestCase::LiIonEnergyTestCase
LiIonEnergyTestCase()
Definition:
li-ion-energy-source-test.cc:45
src
energy
test
li-ion-energy-source-test.cc
Generated on Sat Apr 19 2014 14:06:54 for ns-3 by
1.8.6