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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
7 */
8
9#include "ns3/li-ion-energy-source.h"
10#include "ns3/log.h"
11#include "ns3/node.h"
12#include "ns3/simple-device-energy-model.h"
13#include "ns3/simulator.h"
14#include "ns3/test.h"
15
16using namespace ns3;
17using namespace ns3::energy;
18
19// NS_DEPRECATED_3_43() - tag for future removal
20// LiIonEnergySource was deprecated in commit
21// https://gitlab.com/nsnam/ns-3-dev/-/commit/086913b0
22//
23// The new battery model is illustrated in
24// `src/energy/examples/generic-battery-discharge-example.cc`
25//
26// A GenericBatteryModelTestCase is being developed in MR 2181
27// https://gitlab.com/nsnam/ns-3-dev/-/merge_requests/2181
28// which will be in
29// `src/energy/test/generic-battery-model-test.cc`
30
31NS_LOG_COMPONENT_DEFINE("LiIonEnergySourceTestSuite");
32
33/**
34 * \ingroup energy-tests
35 *
36 * \brief LiIon battery Test
37 */
39{
40 public:
42 ~LiIonEnergyTestCase() override;
43
44 void DoRun() override;
45
46 Ptr<Node> m_node; //!< Node to aggreagte the source to.
47};
48
50 : TestCase("Li-Ion energy source test case")
51{
52}
53
58
59void
61{
63
65
69
70 es->SetNode(m_node);
71 sem->SetEnergySource(es);
72 es->AppendDeviceEnergyModel(sem);
74
75 Time now = Simulator::Now();
76
77 // discharge at 2.33 A for 1700 seconds
78 sem->SetCurrentA(2.33);
79 now += Seconds(1701);
80
81 Simulator::Stop(now);
84
85 NS_TEST_ASSERT_MSG_EQ_TOL(es->GetSupplyVoltage(), 3.6, 1.0e-3, "Incorrect consumed energy!");
86}
87
88/**
89 * \ingroup energy-tests
90 *
91 * \brief LiIon battery TestSuite
92 */
94{
95 public:
97};
98
100 : TestSuite("li-ion-energy-source", Type::UNIT)
101{
102 AddTestCase(new LiIonEnergyTestCase, TestCase::Duration::QUICK);
103}
104
105/// 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:298
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
#define NS_WARNING_POP
Pops the diagnostic warning list from the stack, restoring it to the previous state.
Definition warnings.h:102
#define NS_WARNING_PUSH_DEPRECATED
Save the current warning list and disables the ones about deprecated functions and classes.
Definition warnings.h:114
static LiIonEnergySourceTestSuite g_liIonEnergySourceTestSuite
create an instance of the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.