A Discrete-Event Network Simulator
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
27using namespace ns3;
28
29NS_LOG_COMPONENT_DEFINE("LiIonEnergySourceTestSuite");
30
31/**
32 * \ingroup energy-tests
33 *
34 * \brief LiIon battery Test
35 */
37{
38 public:
40 ~LiIonEnergyTestCase() override;
41
42 void DoRun() override;
43
44 Ptr<Node> m_node; //!< Node to aggreagte the source to.
45};
46
48 : TestCase("Li-Ion energy source test case")
49{
50}
51
53{
54 m_node = nullptr;
55}
56
57void
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);
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);
79
80 NS_TEST_ASSERT_MSG_EQ_TOL(es->GetSupplyVoltage(), 3.6, 1.0e-3, "Incorrect consumed energy!");
81}
82
83/**
84 * \ingroup energy-tests
85 *
86 * \brief LiIon battery TestSuite
87 */
89{
90 public:
92};
93
95 : TestSuite("li-ion-energy-source", Type::UNIT)
96{
97 AddTestCase(new LiIonEnergyTestCase, TestCase::Duration::QUICK);
98}
99
100/// create an instance of the test suite
void DoRun() override
Implementation to actually run this TestCase.
Ptr< Node > m_node
Node to aggreagte the source to.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:309
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.