diff --git a/Software/PC_Application/LibreVNA-GUI/Calibration/calibration.h b/Software/PC_Application/LibreVNA-GUI/Calibration/calibration.h index 07946b7..73248f7 100644 --- a/Software/PC_Application/LibreVNA-GUI/Calibration/calibration.h +++ b/Software/PC_Application/LibreVNA-GUI/Calibration/calibration.h @@ -14,6 +14,7 @@ class Calibration : public QObject, public Savable, public SCPINode Q_OBJECT friend class LibreCALDialog; + friend class CalibrationTests; public: Calibration(); @@ -130,7 +131,7 @@ private: void createDefaultMeasurements(DefaultMeasurements dm); void deleteMeasurements(); - bool hasFrequencyOverlap(std::vector m, double *startFreq = nullptr, double *stopFreq = nullptr, int *points = nullptr, bool *isLog = nullptr); + static bool hasFrequencyOverlap(std::vector m, double *startFreq = nullptr, double *stopFreq = nullptr, int *points = nullptr, bool *isLog = nullptr); // returns all measurements that match the paramaters std::vector findMeasurements(CalibrationMeasurement::Base::Type type, int port1 = 0, int port2 = 0); // returns the first measurement in the list that matches the parameters diff --git a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro index bf0872e..fe883f3 100644 --- a/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro +++ b/Software/PC_Application/LibreVNA-Test/LibreVNA-Test.pro @@ -154,6 +154,7 @@ SOURCES += \ ../LibreVNA-GUI/streamingserver.cpp \ ../LibreVNA-GUI/touchstone.cpp \ ../LibreVNA-GUI/unit.cpp \ + calibrationtests.cpp \ ffttests.cpp \ impedancerenormalizationtests.cpp \ main.cpp \ @@ -352,6 +353,7 @@ HEADERS += \ ../LibreVNA-GUI/streamingserver.h \ ../LibreVNA-GUI/touchstone.h \ ../LibreVNA-GUI/unit.h \ + calibrationtests.h \ ffttests.h \ impedancerenormalizationtests.h \ parametertests.h \ diff --git a/Software/PC_Application/LibreVNA-Test/calibrationtests.cpp b/Software/PC_Application/LibreVNA-Test/calibrationtests.cpp new file mode 100644 index 0000000..8fb1358 --- /dev/null +++ b/Software/PC_Application/LibreVNA-Test/calibrationtests.cpp @@ -0,0 +1,136 @@ +#include "calibrationtests.h" + +#include "calibration.h" + +CalibrationTests::CalibrationTests() {} + +void CalibrationTests::LinearDetection() +{ + // create some measurements + std::vector m; + double startFreq = 100000; + double stopFreq = 6000000000; + int points = 1001; + Calibration cal; + cal.getKit().setIdealDefault(); + auto open = new CalibrationMeasurement::Open(&cal); + open->setPort(1); + m.push_back(open); + auto _short = new CalibrationMeasurement::Short(&cal); + _short->setPort(1); + m.push_back(_short); + auto load = new CalibrationMeasurement::Load(&cal); + load->setPort(1); + m.push_back(load); + + for(int i=0;iaddPoint(meas); + m[1]->addPoint(meas); + m[2]->addPoint(meas); + } + + // verify correct detection + double detectedStart; + double detectedStop; + int detectedPoints; + bool detectedLog; + Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog); + + QVERIFY(qFuzzyCompare(detectedStart, startFreq)); + QVERIFY(qFuzzyCompare(detectedStop, stopFreq)); + QVERIFY(detectedPoints == points); + QVERIFY(detectedLog == false); +} + +void CalibrationTests::LogDetection() +{ + // create some measurements + std::vector m; + double startFreq = 100000; + double stopFreq = 6000000000; + int points = 1001; + Calibration cal; + cal.getKit().setIdealDefault(); + auto open = new CalibrationMeasurement::Open(&cal); + open->setPort(1); + m.push_back(open); + auto _short = new CalibrationMeasurement::Short(&cal); + _short->setPort(1); + m.push_back(_short); + auto load = new CalibrationMeasurement::Load(&cal); + load->setPort(1); + m.push_back(load); + + for(int i=0;iaddPoint(meas); + m[1]->addPoint(meas); + m[2]->addPoint(meas); + } + + // verify correct detection + double detectedStart; + double detectedStop; + int detectedPoints; + bool detectedLog; + Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog); + + QVERIFY(qFuzzyCompare(detectedStart, startFreq)); + QVERIFY(qFuzzyCompare(detectedStop, stopFreq)); + QVERIFY(detectedPoints == points); + QVERIFY(detectedLog == true); +} + +void CalibrationTests::MixedDetection() +{ + // create some measurements + std::vector m; + double startFreq = 100000; + double stopFreq = 6000000000; + int points = 1001; + Calibration cal; + cal.getKit().setIdealDefault(); + auto open = new CalibrationMeasurement::Open(&cal); + open->setPort(1); + m.push_back(open); + auto _short = new CalibrationMeasurement::Short(&cal); + _short->setPort(1); + m.push_back(_short); + auto load = new CalibrationMeasurement::Load(&cal); + load->setPort(1); + m.push_back(load); + + for(int i=0;iaddPoint(measlin); + m[1]->addPoint(measlog); + m[2]->addPoint(measlog); + } + + // verify correct detection + double detectedStart; + double detectedStop; + int detectedPoints; + bool detectedLog; + Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog); + + QVERIFY(qFuzzyCompare(detectedStart, startFreq)); + QVERIFY(qFuzzyCompare(detectedStop, stopFreq)); + QVERIFY(detectedPoints == points); + QVERIFY(detectedLog == true); +} diff --git a/Software/PC_Application/LibreVNA-Test/calibrationtests.h b/Software/PC_Application/LibreVNA-Test/calibrationtests.h new file mode 100644 index 0000000..0602a7d --- /dev/null +++ b/Software/PC_Application/LibreVNA-Test/calibrationtests.h @@ -0,0 +1,18 @@ +#ifndef CALIBRATIONTESTS_H +#define CALIBRATIONTESTS_H + +#include + +class CalibrationTests : public QObject +{ + Q_OBJECT +public: + CalibrationTests(); + +private slots: + void LinearDetection(); + void LogDetection(); + void MixedDetection(); +}; + +#endif // CALIBRATIONTESTS_H diff --git a/Software/PC_Application/LibreVNA-Test/main.cpp b/Software/PC_Application/LibreVNA-Test/main.cpp index 7456941..f9f2868 100644 --- a/Software/PC_Application/LibreVNA-Test/main.cpp +++ b/Software/PC_Application/LibreVNA-Test/main.cpp @@ -3,6 +3,7 @@ #include "parametertests.h" #include "ffttests.h" #include "impedancerenormalizationtests.h" +#include "calibrationtests.h" #include @@ -16,6 +17,7 @@ int main(int argc, char *argv[]) status |= QTest::qExec(new ParameterTests, argc, argv); status |= QTest::qExec(new fftTests, argc, argv); status |= QTest::qExec(new ImpedanceRenormalizationTests, argc, argv); + status |= QTest::qExec(new CalibrationTests, argc, argv); return status; }