mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-21 06:13:41 +00:00
Move project, add simple test
This commit is contained in:
parent
fc1d006edd
commit
a58b705f08
762 changed files with 266 additions and 249581 deletions
65
Software/PC_Application/LibreVNA-Test/utiltests.cpp
Normal file
65
Software/PC_Application/LibreVNA-Test/utiltests.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#include "utiltests.h"
|
||||
|
||||
#include <vector>
|
||||
#include "util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
UtilTests::UtilTests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UtilTests::IdealCircleApproximation()
|
||||
{
|
||||
vector<complex<double>> points;
|
||||
// create ideal circle points
|
||||
auto center = complex<double>(2.34, 4.12);
|
||||
auto radius = 5.0;
|
||||
static constexpr int numPoints = 10;
|
||||
for(int i=0;i<numPoints;i++) {
|
||||
auto angle = 2*M_PI * i / numPoints;
|
||||
auto offset = polar(radius, angle);
|
||||
points.push_back(center + offset);
|
||||
}
|
||||
auto circCenter = Util::findCenterOfCircle(points);
|
||||
QVERIFY(qFuzzyCompare(center.real(), circCenter.real()));
|
||||
QVERIFY(qFuzzyCompare(center.imag(), circCenter.imag()));
|
||||
}
|
||||
|
||||
void UtilTests::IdealArcApproximation()
|
||||
{
|
||||
vector<complex<double>> points;
|
||||
// create ideal circle points
|
||||
auto center = complex<double>(2.34, 4.12);
|
||||
auto radius = 5.0;
|
||||
static constexpr int numPoints = 10;
|
||||
for(int i=0;i<numPoints;i++) {
|
||||
auto angle = 0.1*2*M_PI * i / numPoints;
|
||||
auto offset = polar(radius, angle);
|
||||
points.push_back(center + offset);
|
||||
}
|
||||
auto circCenter = Util::findCenterOfCircle(points);
|
||||
QVERIFY(qFuzzyCompare(center.real(), circCenter.real()));
|
||||
QVERIFY(qFuzzyCompare(center.imag(), circCenter.imag()));
|
||||
}
|
||||
|
||||
void UtilTests::NoisyCircleApproximation()
|
||||
{
|
||||
srand(0);
|
||||
vector<complex<double>> points;
|
||||
// create ideal circle points
|
||||
auto center = complex<double>(2.34, 4.12);
|
||||
auto radius = 5.0;
|
||||
static constexpr int numPoints = 10;
|
||||
for(int i=0;i<numPoints;i++) {
|
||||
auto angle = 2*M_PI * i / numPoints;
|
||||
auto offset = polar(radius, angle);
|
||||
auto noise = polar(0.1*(double)rand() / RAND_MAX, 2*M_PI*(double)rand() / RAND_MAX);
|
||||
points.push_back(center + offset + noise);
|
||||
}
|
||||
auto circCenter = Util::findCenterOfCircle(points);
|
||||
constexpr double maxDelta = 0.1;
|
||||
QVERIFY(abs(center.real() - circCenter.real()) <= maxDelta);
|
||||
QVERIFY(abs(center.imag() - circCenter.imag()) <= maxDelta);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue