owlps/owlps-positioning/tests/measurement_test.hh

104 lines
2.3 KiB
C++

#include <cxxtest/TestSuite.h>
#include "measurement.hh"
class Measurement_test: public CxxTest::TestSuite
{
public:
void test_constructors(void)
{
// Default constructor
Measurement m00 ;
std::vector<int> vi1 ;
Measurement m01(NULL, vi1) ;
TS_ASSERT_EQUALS(m00, m01) ;
// Copy constructor
AccessPoint ap1 ;
Measurement m1(&ap1) ;
Measurement m2(m1) ;
TS_ASSERT_EQUALS(m1, m2) ;
}
void test_accessors(void)
{
// Simple read accessors
AccessPoint ap1 ;
std::vector<int> vi1 ;
Measurement m1(&ap1, vi1) ;
TS_ASSERT_EQUALS(m1.get_ap(), &ap1) ;
TS_ASSERT_EQUALS(m1.get_ss_list(), vi1) ;
TS_ASSERT_EQUALS(m1.get_average_ss(), 0) ;
// Write & read accessors
AccessPoint ap2 ;
m1.set_ap(&ap2) ;
TS_ASSERT_EQUALS(m1.get_ap(), &ap2) ;
m1.add_ss(-33) ;
m1.add_ss(-78) ;
m1.add_ss(-21) ;
vi1.push_back(-33) ;
vi1.push_back(-78) ;
vi1.push_back(-21) ;
TS_ASSERT_EQUALS(m1.get_ss_list(), vi1) ;
/* *** Average computation ***
*
* We need to convert all dBm values into mW, compute the average
* and convert mW back to dBm.
* (1) P[mW] = 10^(P[dBm] / 10)
* (2) P[dBm] = 10 log10(P[mW])
*
* So for the dBm values -33, -78, -21, we have:
* -33 dBm = 10^(-33/10) mW = 0.0005012 mW
* -78 dBm = 10^(-78/10) mW = 0.00000001585 mW
* -21 dBm = 10^(-21/10) mW = 0.0079433 mW
* And:
* ( 10^(-33/10) + 10^(-78/10) + 10^(-21/10) ) / 3 = 0.0028148 mW
* Back to dBm:
* 0.0028148 mW = -25.505481 dBm
*/
TS_ASSERT_DELTA(m1.get_average_ss(), -25.505481, 0.0001) ;
m1.clear() ;
std::vector<int> vi2 ;
vi2.push_back(-54) ;
vi2.push_back(-1) ;
m1.set_ss_list(vi2) ;
TS_ASSERT_EQUALS(m1.get_ss_list(), vi2) ;
TS_ASSERT_DELTA(m1.get_average_ss(), -4.0102782, 0.0001) ;
m1.clear() ;
Measurement m2 ;
TS_ASSERT_EQUALS(m1, m2) ;
}
void test_operators(void)
{
// ==
AccessPoint ap1 ;
Measurement m1(&ap1) ;
Measurement m2(&ap1) ;
TS_ASSERT_EQUALS(m1, m2) ;
// !=
AccessPoint ap2 ;
Measurement m3(&ap2) ;
TS_ASSERT_DIFFERS(m1, m3) ;
// =
m2 = m3 ;
TS_ASSERT_EQUALS(m2, m3) ;
// bool
TS_ASSERT(m1) ;
Measurement m4 ;
TS_ASSERT(! m4) ;
}
} ;