/*
 * 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 "direction.hh"
#include "posexcept.hh"

class Direction_test: public CxxTest::TestSuite
{
public:

  void test_constructors(void)
  {
    // Default constructor
    TS_ASSERT_THROWS_NOTHING(Direction()) ;

    // int constructor
    // 0 is accepted, although it doesn't create a valid Direction
    TS_ASSERT_THROWS_NOTHING(Direction(0)) ;
    TS_ASSERT_THROWS(Direction(5), bad_direction) ;

    TS_ASSERT_THROWS_NOTHING(Direction(north)) ;
    // FIXME: I wonder why north works but not Direction::north…
    TS_ASSERT_THROWS_NOTHING(Direction(east)) ;
    TS_ASSERT_THROWS_NOTHING(Direction(south)) ;
    TS_ASSERT_THROWS_NOTHING(Direction(west)) ;

    // Copy constructor
    Direction direction1(Direction::north) ;
    Direction direction2(direction1) ;
    TS_ASSERT_EQUALS(direction1, direction2) ;
  }


  void test_accessors(void)
  {
    Direction direction0 ;
    Direction direction1(Direction::south) ;
    direction1.clear() ;
    TS_ASSERT(! direction1) ;
    TS_ASSERT_EQUALS(direction0, direction1) ;
  }


  void test_operators(void)
  {
    Direction direction0 ;
    Direction direction1(Direction::north) ;
    Direction direction2(Direction::east) ;
    Direction direction3(Direction::south) ;
    Direction direction4(Direction::west) ;

    // ==
    Direction direction5(Direction::north) ;
    TS_ASSERT_EQUALS(direction1, direction5) ;

    // =
    Direction direction6 = direction5 ;
    TS_ASSERT_EQUALS(direction5, direction6) ;

    // !=
    direction6 = direction4 ;
    TS_ASSERT(direction5 != direction6) ;

    // bool
    TS_ASSERT(! direction0) ;
    TS_ASSERT(direction1) ;
    TS_ASSERT(direction2) ;
    TS_ASSERT(direction3) ;
    TS_ASSERT(direction4) ;

    // int
    TS_ASSERT_EQUALS(static_cast<int>(direction1),
                     static_cast<int>(Direction::north)) ;
    TS_ASSERT_EQUALS(static_cast<int>(direction2),
                     static_cast<int>(Direction::east)) ;
    TS_ASSERT_EQUALS(static_cast<int>(direction3),
                     static_cast<int>(Direction::south)) ;
    TS_ASSERT_EQUALS(static_cast<int>(direction4),
                     static_cast<int>(Direction::west)) ;

    // string
    TS_ASSERT_EQUALS(static_cast<std::string>(direction1), "north") ;
    TS_ASSERT_EQUALS(static_cast<std::string>(direction2), "east") ;
    TS_ASSERT_EQUALS(static_cast<std::string>(direction3), "south") ;
    TS_ASSERT_EQUALS(static_cast<std::string>(direction4), "west") ;
  }

} ;
