10#include "ns3/basic-energy-harvester.h"
11#include "ns3/basic-energy-source.h"
12#include "ns3/config.h"
13#include "ns3/double.h"
16#include "ns3/simulator.h"
17#include "ns3/string.h"
36 void DoRun()
override;
46 :
TestCase(
"Basic Energy Harvester test case")
68 node->AggregateObject(source);
74 harvester->SetHarvestedPowerUpdateInterval(
Seconds(
m_timeS + 1.0));
76 source->ConnectEnergyHarvester(harvester);
77 harvester->SetNode(node);
78 harvester->SetEnergySource(source);
89 double timeDelta = 0.000000001;
95 double estRemainingEnergy = source->GetInitialEnergy();
97 estRemainingEnergy += harvester->GetPower() *
m_timeS;
100 double remainingEnergy = source->GetRemainingEnergy();
101 NS_LOG_DEBUG(
"Remaining energy is " << remainingEnergy);
102 NS_LOG_DEBUG(
"Estimated remaining energy is " << estRemainingEnergy);
103 NS_LOG_DEBUG(
"Difference is " << estRemainingEnergy - remainingEnergy);
111 "Incorrect Remaining energy!");
static BasicEnergyHarvesterTestSuite g_basicEnergyHarvesterTestSuite
create an instance of the test suite
~BasicEnergyHarvesterTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
ObjectFactory m_energySource
Energy source factory.
ObjectFactory m_energyHarvester
Energy harvester factory.
double m_timeS
Time, in seconds.
double m_tolerance
Tolerance for energy estimation.
BasicEnergyHarvesterTestCase()
Energy harvester TestSuite.
BasicEnergyHarvesterTestSuite()
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
BasicEnergyHarvester increases remaining energy stored in an associated Energy Source.
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
void UpdateEnergySource() override
Implements UpdateEnergySource.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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...
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.