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;
28using namespace ns3::energy;
29
30NS_LOG_COMPONENT_DEFINE("LiIonEnergySourceTestSuite");
31
32/**
33 * \ingroup energy-tests
34 *
35 * \brief LiIon battery Test
36 */
38{
39 public:
41 ~LiIonEnergyTestCase() override;
42
43 void DoRun() override;
44
45 Ptr<Node> m_node; //!< Node to aggreagte the source to.
46};
47
49 : TestCase("Li-Ion energy source test case")
50{
51}
52
54{
55 m_node = nullptr;
56}
57
58void
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);
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);
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 */
90{
91 public:
93};
94
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
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:302
A suite of tests to run.
Definition: test.h:1273
Type
Type of test.
Definition: test.h:1280
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.