/*
 * This file is part of the Owl Positioning System (OwlPS) project.
 * It is subject to the copyright notice and license terms in the
 * COPYRIGHT.t2t file found in the top-level directory of this
 * distribution and at
 *   https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
 * No part of the OwlPS Project, including this file, may be copied,
 * modified, propagated, or distributed except according to the terms
 * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
 * distributed along with this file, either separately or by replacing
 * this notice by the COPYRIGHT.t2t file's contents.
 */

#include <cxxtest/TestSuite.h>

#include "interlinknetworks.hh"

class InterlinkNetworks_test: public CxxTest::TestSuite
{
public:

  void test_distance(void)
  {
    TrilaterationAlgorithm *algo = new InterlinkNetworks() ;

    // Initialise algo->request
    float mobile_gain = 3, mobile_power = 15 ;
    Mobile mobile("", "", mobile_gain, mobile_power) ;
    Request request(&mobile) ;
    algo->compute(request) ; // yes, that's ugly

    float ap_gain = 5, ap_power = 20 ;
    unsigned int ap_channel = 1 ;
    CapturePoint ap(Point3D(), "", "", ap_gain, ap_power, ap_channel) ;

    std::map<pkt_id_t, ss_t> ss_list ;
    ss_list[1] = -42 ;
    Measurement measurement(&ap) ;
    measurement.add_ss_list(ss_list) ;

    /* To check ref_distance in Scilab:
       mobile_gain = 3
       mobile_power = 15
       ap_gain = 5
       celerity = 299792458
       frequency = 2412000000
       C = mobile_gain + mobile_power + ap_gain + 20 * log10(celerity / frequency / (4 * %pi))
       L = -42
       ref_distance = 10^((C-L)/35)
     */
    float ref_distance = 5.1470931 ;

    float computed_distance = algo->estimate_distance(measurement) ;
    TS_ASSERT_DELTA(computed_distance, ref_distance, 0.0001) ;

    delete algo ;
  }

} ;
