From 7df91546daff4f3cfb9b124a3df13a9bf0a686c0 Mon Sep 17 00:00:00 2001 From: Tim Schubert Date: Sat, 15 Aug 2020 12:59:32 +0200 Subject: [PATCH] Add test for offset --- model/leo-circular-orbit-mobility-model.cc | 2 +- test/leo-orbit-test-suite.cc | 33 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/model/leo-circular-orbit-mobility-model.cc b/model/leo-circular-orbit-mobility-model.cc index b8f0eb2..d2bce7d 100644 --- a/model/leo-circular-orbit-mobility-model.cc +++ b/model/leo-circular-orbit-mobility-model.cc @@ -105,7 +105,7 @@ double LeoCircularOrbitMobilityModel::GetProgress (Time t) const { // TODO use nanos or ms instead? does it give higher precision? - return 2 * M_PI * ((GetSpeed () * t.GetSeconds ()) / LEO_EARTH_RAD_M); + return 2 * M_PI * ((GetSpeed () * t.GetSeconds ()) / LEO_EARTH_RAD_M) + m_offset; } Vector3D diff --git a/test/leo-orbit-test-suite.cc b/test/leo-orbit-test-suite.cc index 404dc93..5fb2c9e 100644 --- a/test/leo-orbit-test-suite.cc +++ b/test/leo-orbit-test-suite.cc @@ -42,13 +42,14 @@ private: class LeoOrbitProgressTestCase : public TestCase { public: - LeoOrbitProgressTestCase () : TestCase ("Test position for 0 altitude and 0 inclination after 60 seconds") {} + LeoOrbitProgressTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination after 360 seconds") {} virtual ~LeoOrbitProgressTestCase () {} private: - void TestLengthPosition (double expected, Ptr mob) + void TestLengthPosition (double expl, double expx, Ptr mob) { Vector pos = mob->GetPosition (); - NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength (), expected, 0.001, "Position not equal", __FILE__, __LINE__); + NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position not equal", __FILE__, __LINE__); + NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength (), expl, 0.001, "Position must be different", __FILE__, __LINE__); } virtual void DoRun (void) @@ -57,12 +58,33 @@ private: mob->SetAttribute ("Altitude", DoubleValue (0.0)); mob->SetAttribute ("Inclination", DoubleValue (1.0)); - Simulator::Schedule (Seconds (360.0), &LeoOrbitProgressTestCase::TestLengthPosition, this, LEO_EARTH_RAD_M, mob); + Vector pos = mob->GetPosition (); + Simulator::Schedule (Seconds (360.0), &LeoOrbitProgressTestCase::TestLengthPosition, this, LEO_EARTH_RAD_M, pos.x, mob); Simulator::Run (); Simulator::Destroy (); } }; -// TODO offset + +class LeoOrbitOffsetTestCase : public TestCase +{ +public: + LeoOrbitOffsetTestCase () : TestCase ("Test offset between neighboring satellites") {} + virtual ~LeoOrbitOffsetTestCase () {} +private: + virtual void DoRun (void) + { + Ptr mob = CreateObject (); + mob->SetAttribute ("Altitude", DoubleValue (1000.0)); + mob->SetAttribute ("Inclination", DoubleValue (20.0)); + + Vector pos1 = mob->GetPosition (); + + mob->SetAttribute ("Offset", DoubleValue (20.0)); + Vector pos2 = mob->GetPosition (); + + NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position"); + } +}; class LeoOrbitTestSuite : TestSuite { @@ -71,6 +93,7 @@ public: AddTestCase (new LeoOrbitSpeedTestCase, TestCase::QUICK); AddTestCase (new LeoOrbitPositionTestCase, TestCase::QUICK); AddTestCase (new LeoOrbitProgressTestCase, TestCase::QUICK); + AddTestCase (new LeoOrbitOffsetTestCase, TestCase::QUICK); } };