21#include "ns3/basic-energy-harvester.h"
22#include "ns3/basic-energy-source.h"
23#include "ns3/config.h"
24#include "ns3/double.h"
27#include "ns3/simulator.h"
28#include "ns3/string.h"
46 void DoRun()
override;
56 :
TestCase(
"Basic Energy Harvester test case")
78 node->AggregateObject(source);
84 harvester->SetHarvestedPowerUpdateInterval(
Seconds(
m_timeS + 1.0));
86 source->ConnectEnergyHarvester(harvester);
87 harvester->SetNode(node);
88 harvester->SetEnergySource(source);
99 double timeDelta = 0.000000001;
105 double estRemainingEnergy = source->GetInitialEnergy();
107 estRemainingEnergy += harvester->GetPower() *
m_timeS;
110 double remainingEnergy = source->GetRemainingEnergy();
111 NS_LOG_DEBUG(
"Remaining energy is " << remainingEnergy);
112 NS_LOG_DEBUG(
"Estimated remaining energy is " << estRemainingEnergy);
113 NS_LOG_DEBUG(
"Difference is " << estRemainingEnergy - remainingEnergy);
121 "Incorrect Remaining energy!");
136 :
TestSuite(
"basic-energy-harvester", UNIT)
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()
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.
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, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
#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.
#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.