/*
 * 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 "result.hh"
#include "request.hh"

class Result_test: public CxxTest::TestSuite
{
public:

  void test_constructors(void)
  {
    // Default constructor
    Result result1 ;
    Result result2(nullptr) ;
    Result result3(nullptr, "UnknownAlgorithm") ;
    TS_ASSERT_EQUALS(result1, result2) ;
    TS_ASSERT_EQUALS(result1, result3) ;

    Request request1 ;
    Result result4(&request1) ;
    TS_ASSERT(result1 != result4) ;
  }

  void test_accessors(void)
  {
    // We cannot test easily in_which_area() without a complete
    // configuration.

    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(timestamp1) ;
    Point3D point3d1(3,4,2) ;
    Result result1(&request1, "MyAlgorithm", point3d1) ;

    TS_ASSERT_EQUALS(result1.get_position(), point3d1) ;
    TS_ASSERT_EQUALS(result1.get_request(), &request1) ;
    TS_ASSERT_EQUALS(result1.get_error(), -1) ;
  }

  void test_error(void)
  {
    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(timestamp1) ;
    Point3D position(1, 1, 1), real_position(1, 5, 1) ;
    Result result1(&request1, "MyAlgorithm", position, real_position) ;
    TS_ASSERT_EQUALS(result1.get_error(), 4) ;

    Point3D real_position2(1, 3.5, 1) ;
    result1.compute_error(real_position2) ;
    TS_ASSERT_EQUALS(result1.get_error(), 2.5) ;
  }

  void test_operators(void)
  {
    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(timestamp1) ;
    Point3D point3d1(3,4,2) ;
    Result result1(&request1, point3d1) ;
    Result result2(&request1, point3d1) ;
    TS_ASSERT_EQUALS(result1, result2) ;

    Result result3 ;
    TS_ASSERT(result1 != result3) ;

    result3 = result1 ;
    TS_ASSERT_EQUALS(result1, result3) ;
  }

} ;
