Skip to content

Commit

Permalink
epsilon > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
cheroy-ntia committed Nov 26, 2024
1 parent d1ec139 commit 48db825
Show file tree
Hide file tree
Showing 6 changed files with 8,511 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ResidueSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ double ResidueSeries(double k, double h_1__km, double h_2__km, double nu, double

if (i != 0)
{
//if ((abs((GW * GW).real()) + (abs((GW * GW).imag()))) == 0.0) // when the ground wave is too small close to 0.
//if ((abs((GW * GW).real()) + (abs((GW * GW).imag()))) == 0.0) { // when the ground wave is too small close to 0.
// Replaced with AlmostEqualRelative
if (AlmostEqualRelative((abs((GW * GW).real()) + (abs((GW * GW).imag()))), 0.0)) {
return 0; // end the loop and output E = 0
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ add_executable(
${TEST_NAME}
"LFMFUnitTest.cpp"
"TestLFMFReturnCode.cpp"
"TestLFMFEquivalence.cpp"
"TestLFMFPolarizationHorizontal.cpp"
"TestLFMFPolarizationVertical.cpp"
"LFMFGTestUtils.cpp"
"LFMFGTest.h"
)
Expand Down
101 changes: 101 additions & 0 deletions tests/TestLFMFPolarizationHorizontal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/** @file TestLFMFPolarizationHorizontal.cpp
* Implements the google tests from ITS.Propagation.LFMF.
*/

#include "LFMFGTest.h"

/******************************************************************************
*
* Description: The purpose of this is to ensure that the LFMF model
* executes the same results as matlab code.
* Test Data are from https://github.com/eeveetza/LFMFSmoothEarth.
*
*****************************************************************************/
class TestLFMFPolarizationHorizontal: public ::testing::Test {
protected:
void SetUp() override {
// Load test data from CSV
testData = ReadLFMFInputsAndResult(fileName);
}

// Vector to hold test data
std::vector<LFMFInputsAndResult> testData;

std::string fileName = "ValidationPolarizationHorizontal.csv";
};

/******************************************************************************
*
* Description: Test case to verify LFMF Flat earth curve method results are correct
*
*****************************************************************************/
TEST_F(TestLFMFPolarizationHorizontal, FlatEarthCurveMethodEquivalentToMatLAB) {
// Ensure test data was loaded
EXPECT_NE(static_cast<int>(testData.size()), 0);
int i = 0;
for (const auto &data : testData) {
if (data.expectedResult.method == METHOD__FLAT_EARTH_CURVE) {
i++;
Result result;
if (i % 100 == 0) {
std::cout << " Test instance: " << i << std::endl;
}
int rtn = LFMF(
data.h_tx__meter,
data.h_rx__meter,
data.f__mhz,
data.P_tx__watt,
data.N_s,
data.d__km,
data.epsilon,
data.sigma,
data.pol,
&result
);

EXPECT_EQ(rtn, SUCCESS);
compareDouble(data.expectedResult.A_btl__db, result.A_btl__db);
compareDouble(data.expectedResult.E_dBuVm, result.E_dBuVm);
compareDouble(data.expectedResult.P_rx__dbm, result.P_rx__dbm);
EXPECT_EQ(result.method, data.expectedResult.method);
}
}
};

/******************************************************************************
*
* Description: Test case to verify LFMF Residue series method results are correct
*
*****************************************************************************/
TEST_F(TestLFMFPolarizationHorizontal, ResidueSeriesMethodEquivalentToMatLAB) {
// Ensure test data was loaded
EXPECT_NE(static_cast<int>(testData.size()), 0);
int i = 0;
for (const auto &data : testData) {
if (data.expectedResult.method == METHOD__RESIDUE_SERIES) {
i++;
Result result;
if (i % 100 == 0) {
std::cout << " Test instance: " << i << std::endl;
}
int rtn = LFMF(
data.h_tx__meter,
data.h_rx__meter,
data.f__mhz,
data.P_tx__watt,
data.N_s,
data.d__km,
data.epsilon,
data.sigma,
data.pol,
&result
);

EXPECT_EQ(rtn, SUCCESS);
compareDouble(data.expectedResult.A_btl__db, result.A_btl__db);
compareDouble(data.expectedResult.E_dBuVm, result.E_dBuVm);
compareDouble(data.expectedResult.P_rx__dbm, result.P_rx__dbm);
EXPECT_EQ(result.method, data.expectedResult.method);
}
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @file TestLFMFEquivalence.cpp
/** @file TestLFMFPolarizationVertical.cpp
* Implements the google tests from ITS.Propagation.LFMF.
*/

Expand All @@ -11,7 +11,7 @@
* Test Data are from https://github.com/eeveetza/LFMFSmoothEarth.
*
*****************************************************************************/
class TestLFMFEquivalence: public ::testing::Test {
class TestLFMFPolarizationVertical: public ::testing::Test {
protected:
void SetUp() override {
// Load test data from CSV
Expand All @@ -21,15 +21,15 @@ class TestLFMFEquivalence: public ::testing::Test {
// Vector to hold test data
std::vector<LFMFInputsAndResult> testData;

std::string fileName = "ValidationExampleLFMFSmoothEarth.csv"; //"ValidationPolarizationHorizontal.csv";
std::string fileName = "ValidationPolarizationVertical.csv";
};

/******************************************************************************
*
* Description: Test case to verify LFMF Flat earth curve method results are correct
*
*****************************************************************************/
TEST_F(TestLFMFEquivalence, FlatEarthCurveMethodEquivalentToMatLAB) {
TEST_F(TestLFMFPolarizationVertical, FlatEarthCurveMethodEquivalentToMatLAB) {
// Ensure test data was loaded
EXPECT_NE(static_cast<int>(testData.size()), 0);
int i = 0;
Expand Down Expand Up @@ -67,7 +67,7 @@ TEST_F(TestLFMFEquivalence, FlatEarthCurveMethodEquivalentToMatLAB) {
* Description: Test case to verify LFMF Residue series method results are correct
*
*****************************************************************************/
TEST_F(TestLFMFEquivalence, ResidueSeriesMethodEquivalentToMatLAB) {
TEST_F(TestLFMFPolarizationVertical, ResidueSeriesMethodEquivalentToMatLAB) {
// Ensure test data was loaded
EXPECT_NE(static_cast<int>(testData.size()), 0);
int i = 0;
Expand Down
Loading

0 comments on commit 48db825

Please sign in to comment.