added missing code changes
started working on refactoring of sensors new test-cases
This commit is contained in:
@@ -48,4 +48,68 @@ TEST(Dijkstra, build) {
|
||||
|
||||
}
|
||||
|
||||
void build(Grid<GP>& grid) {
|
||||
|
||||
const int size = 10000;
|
||||
const int gs = grid.getGridSize_cm();
|
||||
|
||||
for (int x = 0; x < size; x += gs) {
|
||||
for (int y = 0; y < size; y += gs) {
|
||||
grid.add(GP(x,y,0));
|
||||
}
|
||||
}
|
||||
|
||||
std::set<int> done;
|
||||
|
||||
for (int x = 0; x < size; x += gs) {
|
||||
for (int y = 0; y < size; y += gs) {
|
||||
|
||||
const GridPoint gp1(x,y,0);
|
||||
const int idx1 = grid.getNodeFor(gp1).getIdx();
|
||||
|
||||
for (int x1 = -gs; x1 <= +gs; x1 += gs) {
|
||||
for (int y1 = -gs; y1 <= +gs; y1 += gs) {
|
||||
const GridPoint gp2(x+x1, y+y1, 0);
|
||||
if (grid.hasNodeFor(gp2)) {
|
||||
int idx2 = grid.getNodeFor(gp2).getIdx();
|
||||
if (done.find(idx2) != done.end()) {continue;}
|
||||
grid.connectBiDir(idx1, idx2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
done.insert(idx1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void dijkstra(Grid<GP>& grid) {
|
||||
|
||||
class TMP {
|
||||
Grid<GP>& grid;
|
||||
public:
|
||||
TMP(Grid<GP>& grid) : grid(grid) {;}
|
||||
int getNumNeighbors(const GP& node) const {return node.getNumNeighbors();}
|
||||
const GP* getNeighbor(const GP& node, const int idx) const {return &grid.getNeighbor(node, idx);}
|
||||
float getWeightBetween(const GP& n1, const GP& n2) const {return ((Point3)n1 - (Point3)n2).length();}
|
||||
} tmp(grid);
|
||||
|
||||
Dijkstra<GP> d;
|
||||
d.build(grid[0], grid[0], tmp);
|
||||
|
||||
}
|
||||
|
||||
TEST(Dijkstra, huge) {
|
||||
|
||||
|
||||
Grid<GP> grid(10);
|
||||
build(grid);
|
||||
dijkstra(grid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
32
tests/sensors/TestMAC.cpp
Normal file
32
tests/sensors/TestMAC.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../Tests.h"
|
||||
|
||||
#include "../../sensors/MACAddress.h"
|
||||
|
||||
TEST(MAC, ctorSize) {
|
||||
|
||||
ASSERT_THROW(MACAddress("12:34:56:78:9A:A"), std::exception);
|
||||
MACAddress("12:34:56:78:9A:AB");
|
||||
ASSERT_THROW(MACAddress("12:34:56:78:9A:ABC"), std::exception);
|
||||
|
||||
}
|
||||
|
||||
TEST(MAC, caseInsensitive) {
|
||||
|
||||
MACAddress mac1("12:34:56:78:9A:BC");
|
||||
MACAddress mac2("12:34:56:78:9a:bc");
|
||||
ASSERT_EQ(mac1, mac2);
|
||||
|
||||
}
|
||||
|
||||
TEST(MAC, convertLong) {
|
||||
|
||||
MACAddress mac1("12:34:56:78:9A:BC");
|
||||
MACAddress mac2 = MACAddress( mac1.asLong() );
|
||||
ASSERT_EQ(mac1, mac2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
37
tests/sensors/radio/TestLogDistanceModel.cpp
Normal file
37
tests/sensors/radio/TestLogDistanceModel.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../../Tests.h"
|
||||
|
||||
#include "../../../sensors/radio/LogDistanceModel.h"
|
||||
|
||||
TEST(LogDistanceModel, calc) {
|
||||
|
||||
const float txp = -40;
|
||||
const float exp = 1;
|
||||
ASSERT_EQ(-40, LogDistanceModel::distanceToRssi(txp, exp, 1.0));
|
||||
|
||||
// only exponent changed. at 1.0 meter: no difference
|
||||
ASSERT_EQ(LogDistanceModel::distanceToRssi(-40, 1.0, 1.0), LogDistanceModel::distanceToRssi(-40, 2.0, 1.0));
|
||||
|
||||
// distance increment
|
||||
ASSERT_GT(LogDistanceModel::distanceToRssi(-40, 1.0, 1.0), LogDistanceModel::distanceToRssi(-40, 1.0, 2.0));
|
||||
|
||||
// exponent at more than 1.0m
|
||||
ASSERT_GT(LogDistanceModel::distanceToRssi(-40, 1.0, 3.0), LogDistanceModel::distanceToRssi(-40, 1.1, 3.0));
|
||||
|
||||
// other txp
|
||||
ASSERT_GT(LogDistanceModel::distanceToRssi(-40, 1.0, 1.0), LogDistanceModel::distanceToRssi(-45, 1.0, 1.0));
|
||||
|
||||
}
|
||||
|
||||
TEST(LogDistanceModel, forwardBackward) {
|
||||
|
||||
const float txp = -40;
|
||||
const float exp = 1;
|
||||
ASSERT_EQ(1.0, LogDistanceModel::rssiToDistance(txp, exp, LogDistanceModel::distanceToRssi(txp, exp, 1.0)));
|
||||
ASSERT_EQ(5.0, LogDistanceModel::rssiToDistance(txp, exp, LogDistanceModel::distanceToRssi(txp, exp, 5.0)));
|
||||
ASSERT_EQ(10.0, LogDistanceModel::rssiToDistance(txp, exp, LogDistanceModel::distanceToRssi(txp, exp, 10.0)));
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user