/*
 * Project: MoleCuilder
 * Description: creates and alters molecular systems
 * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 *
 *
 *   This file is part of MoleCuilder.
 *
 *    MoleCuilder is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MoleCuilder is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MoleCuilder.  If not, see .
 */
/*
 * ShapeFactoryUnitTest.cpp
 *
 *  Created on: Sep 5, 2012
 *      Author: ankele
 */
// include config.h
#ifdef HAVE_CONFIG_H
#include 
#endif
#include 
#include 
#include 
#include 
#include 
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
#include "CodePatterns/Assert.hpp"
#include "Helpers/defs.hpp"
#include "Shapes/BaseShapes_impl.hpp"
#include "Shapes/Shape_impl.hpp"
#include "Shapes/ShapeFactory.hpp"
#include "ShapeFactoryUnitTest.hpp"
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( ShapeFactoryTest );
void ShapeFactoryTest::setUp()
{
  // failing asserts should be thrown
  ASSERT_DO(Assert::Throw);
  ShapeFactory::getInstance();
}
void ShapeFactoryTest::tearDown()
{
  ShapeFactory::purgeInstance();
}
void ShapeFactoryTest::typeTest()
{
  CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(NowhereType).getType(), NowhereType );
  CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(EverywhereType).getType(), EverywhereType );
  CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(SphereType).getType(), SphereType );
  CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(CuboidType).getType(), CuboidType );
  CPPUNIT_ASSERT_EQUAL( ShapeFactory::getInstance().produce(CylinderType).getType(), CylinderType );
}
void ShapeFactoryTest::resizeTest()
{
  Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(2., 2., 2.));
  CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(0.,1.5,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,1.5) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,2.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,2.) ) );
}
void ShapeFactoryTest::translateTest()
{
  Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(1., 0., 0.));
  CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(1.,.5,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(1.,0.,.5) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,1.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,1.) ) );
  CPPUNIT_ASSERT( !s.isInside( Vector(-.5,0.,0.) ) );
  CPPUNIT_ASSERT( !s.isInside( Vector(0.,-.5,0.) ) );
  CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,-.5) ) );
}
void ShapeFactoryTest::stretchTest()
{
  Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(2., 1., 1.));
  CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
  CPPUNIT_ASSERT( !s.isInside( Vector(0.,1.5,0.) ) );
  CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,1.5) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
}
void ShapeFactoryTest::transformTest()
{
  Shape s = ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(1., 1., 1.), 45., 0., 0.);
  CPPUNIT_ASSERT( s.isInside( Vector(.5,0.,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(0.,.5,0.) ) );
  CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,.5) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
  CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,1.) ) );
}
void ShapeFactoryTest::getterSetterTest()
{
#ifndef NDEBUG
  CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce((ShapeType)-1), Assert::AssertionFailure );
#endif
#ifndef NDEBUG
  CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(0., 0., 0.)), Assert::AssertionFailure );
#endif
#ifndef NDEBUG
  CPPUNIT_ASSERT_THROW( ShapeFactory::getInstance().produce(SphereType, Vector(0., 0., 0.), Vector(1., 1., 0.)), Assert::AssertionFailure );
#endif
}