/*
 * 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 "referencepoint.hh"
#include "calibrationrequest.hh"

class ReferencePoint_test: public CxxTest::TestSuite
{
public:


  void test_constructors(void)
  {
    // Default constructor
    ReferencePoint rp00 ;
    ReferencePoint rp01(0, 0, 0) ;
    TS_ASSERT_EQUALS(rp00, rp01) ;

    // Copy constructor
    ReferencePoint rp1(1, 2, 3) ;
    ReferencePoint rp2(rp1) ;
    TS_ASSERT_EQUALS(rp1, rp2) ;

    // Point3D copy constructor
    Point3D p0(5, 3, 8) ;
    ReferencePoint rp4(p0) ;
    TS_ASSERT_EQUALS(p0, rp4) ;

    // 3-float array constructor
    float coord[3] = {1, 2, 3} ;
    ReferencePoint rp3(coord) ;
    TS_ASSERT_EQUALS(rp1, rp3) ;
  }


  void test_accessors(void)
  {
    // Simple read accessors
    ReferencePoint rp1(1, 3, 5) ;
    TS_ASSERT_EQUALS(rp1.get_x(), 1) ;
    TS_ASSERT_EQUALS(rp1.get_y(), 3) ;
    TS_ASSERT_EQUALS(rp1.get_z(), 5) ;

    // Write & read accessors
    CalibrationRequest
    calibrationrequest1, calibrationrequest2, calibrationrequest3 ;
    rp1.add_request(&calibrationrequest1) ;
    rp1.add_request(&calibrationrequest2) ;
    rp1.add_request(&calibrationrequest3) ;
    std::vector<CalibrationRequest*> vcr1 ;
    vcr1.push_back(&calibrationrequest1) ;
    vcr1.push_back(&calibrationrequest2) ;
    vcr1.push_back(&calibrationrequest3) ;
    TS_ASSERT_EQUALS(rp1.get_requests(), vcr1) ;
    rp1.set_x(42) ;
    TS_ASSERT_EQUALS(rp1.get_x(), 42) ;
    rp1.set_y(321) ;
    TS_ASSERT_EQUALS(rp1.get_y(), 321) ;
    rp1.set_z(98) ;
    TS_ASSERT_EQUALS(rp1.get_z(), 98) ;

    // delete_requests()
    /* Note: as delete_requests() deletes the requests from the Stock,
     * we must store them there first. */
    Stock::find_create_calibration_request(calibrationrequest1) ;
    Stock::find_create_calibration_request(calibrationrequest2) ;
    Stock::find_create_calibration_request(calibrationrequest3) ;
    rp1.delete_requests() ;
    TS_ASSERT(rp1.get_requests().empty()) ;
  }


  void test_operators(void)
  {
    // ==
    ReferencePoint rp1(42, 21, 19) ;
    ReferencePoint rp2(42, 21, 19) ;
    TS_ASSERT_EQUALS(rp1, rp2) ;

    // !=
    ReferencePoint rp3(1, 4, 7) ;
    TS_ASSERT(rp1 != rp3) ;

    // =
    rp2 = rp3 ;
    TS_ASSERT_EQUALS(rp2, rp3) ;

    // <
    TS_ASSERT_LESS_THAN(rp2, rp1) ;

    // <=
    TS_ASSERT_LESS_THAN_EQUALS(rp2, rp1) ;

    // >
    TS_ASSERT(rp1 > rp2) ;

    // >=
    TS_ASSERT(rp1 >= rp2) ;
  }

} ;
