/*
 * 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 "point3d.hh"

class Point3D_test: public CxxTest::TestSuite
{
public:

  void test_constructors(void)
  {
    // Default constructor
    Point3D p00 ;
    Point3D p01(0, 0, 0) ;
    TS_ASSERT_EQUALS(p00, p01) ;

    // Copy constructor
    Point3D p1(1, 2, 3) ;
    Point3D p2(p1) ;
    TS_ASSERT_EQUALS(p1, p2) ;

    // 3-float array constructor
    float coord[3] = {1, 2, 3} ;
    Point3D p3(coord) ;
    TS_ASSERT_EQUALS(p1, p3) ;
  }


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

    // Write & read accessors
    p1.set_x(42) ;
    TS_ASSERT_EQUALS(p1.get_x(), 42) ;
    p1.set_y(321) ;
    TS_ASSERT_EQUALS(p1.get_y(), 321) ;
    p1.set_z(98) ;
    TS_ASSERT_EQUALS(p1.get_z(), 98) ;

    p1.set_coordinates(78, 79, 80) ;
    TS_ASSERT_EQUALS(p1.get_x(), 78) ;
    TS_ASSERT_EQUALS(p1.get_y(), 79) ;
    TS_ASSERT_EQUALS(p1.get_z(), 80) ;

    Point3D p2(4, 5, 6) ;
    p1.set_coordinates(p2) ;
    TS_ASSERT_EQUALS(p1.get_x(), 4) ;
    TS_ASSERT_EQUALS(p1.get_y(), 5) ;
    TS_ASSERT_EQUALS(p1.get_z(), 6) ;

    float p3[3] = {7, 8, 9} ;
    p1.set_coordinates(p3) ;
    TS_ASSERT_EQUALS(p1.get_x(), 7) ;
    TS_ASSERT_EQUALS(p1.get_y(), 8) ;
    TS_ASSERT_EQUALS(p1.get_z(), 9) ;
  }


  void test_distances(void)
  {
    Point3D p1(0, 0, 0) ;
    Point3D p2(1, 0, 0) ;
    TS_ASSERT_EQUALS(p1.distance(p2), 1) ;
    TS_ASSERT_EQUALS(p1.square_distance(p2), 1) ;

    Point3D p3(0, 2, 0) ;
    TS_ASSERT_EQUALS(p1.distance(p3), 2) ;
    TS_ASSERT_EQUALS(p1.square_distance(p3), 4) ;

    Point3D p4(5, 42, 3.2) ;
    Point3D p5(23, 2.4, 0.4) ;
    TS_ASSERT_DELTA(p4.distance(p5), 43.588, 0.001) ;
    TS_ASSERT_DELTA(p4.square_distance(p5), 1900, 0.001) ;

    // TODO: complete this.
  }


  void test_operators(void)
  {
    // ==
    Point3D p1(42, 21, 19) ;
    Point3D p2(42, 21, 19) ;
    TS_ASSERT_EQUALS(p1, p2) ;

    // !=
    Point3D p3(1, 4, 7) ;
    TS_ASSERT(p1 != p3) ;

    // =
    p2 = p3 ;
    TS_ASSERT_EQUALS(p2, p3) ;

    // <
    TS_ASSERT_LESS_THAN(p2, p1) ;

    // <=
    TS_ASSERT_LESS_THAN_EQUALS(p2, p1) ;

    // >
    TS_ASSERT(p1 > p2) ;

    // >=
    TS_ASSERT(p1 >= p2) ;

    // string cast operator
    TS_ASSERT_EQUALS(static_cast<std::string>(p1), "(42;21;19)") ;
  }

} ;
