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")
84 harvester->SetHarvestedPowerUpdateInterval(
Seconds(
m_timeS + 1.0));
87 harvester->SetNode(node);
88 harvester->SetEnergySource(source);
97 Simulator::Schedule(
Seconds(
m_timeS), &BasicEnergySource::UpdateEnergySource, source);
99 double timeDelta = 0.000000001;
107 estRemainingEnergy += harvester->GetPower() *
m_timeS;
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);
115 Simulator::Destroy();
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.
double GetRemainingEnergy() override
double GetInitialEnergy() const override
void ConnectEnergyHarvester(Ptr< EnergyHarvester > energyHarvesterPtr)
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.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
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.
Time Now()
create an ns3::Time instance which contains the current simulation time.
#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.