/*
 * Project: MoleCuilder
 * Description: creates and alters molecular systems
 * Copyright (C)  2012 University of Bonn. All rights reserved.
 * Copyright (C)  2013 Frederik Heber. 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 .
 */
/*
 * SaturatedFragmentUnitTest.cpp
 *
 *  Created on: Aug 09, 2012
 *      Author: heber
 */
// include config.h
#ifdef HAVE_CONFIG_H
#include 
#endif
using namespace std;
#include 
#include 
#include 
// include headers that implement a archive in simple text format
#include 
#include 
#include "SaturatedFragmentUnitTest.hpp"
#include 
#include "CodePatterns/Assert.hpp"
#include "Atom/atom.hpp"
#include "Atom/AtomObserver.hpp"
#include "Element/element.hpp"
#include "Element/periodentafel.hpp"
#include "Fragmentation/HydrogenSaturation_enum.hpp"
#include "molecule.hpp"
#include "World.hpp"
#include "WorldTime.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
using namespace boost::assign;
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( SaturatedFragmentTest );
void SaturatedFragmentTest::setUp()
{
  // failing asserts should be thrown
  ASSERT_DO(Assert::Throw);
  // construct element
  hydrogen = World::getInstance().getPeriode()->FindElement(1);
  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
  oxygen = World::getInstance().getPeriode()->FindElement(8);
  CPPUNIT_ASSERT(oxygen != NULL && "could not find element oxygen");
  // construct molecule (tetraeder of hydrogens)
  TestMolecule = World::getInstance().createMolecule();
  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
  atom * Walker = World::getInstance().createAtom();
  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
  Walker->setType(oxygen);
  Walker->setPosition(Vector(1., 0., 1. ));
  TestMolecule->AddAtom(Walker);
  Walker = World::getInstance().createAtom();
  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
  Walker->setType(hydrogen);
  Walker->setPosition(Vector(0., 1., 1. ));
  TestMolecule->AddAtom(Walker);
  Walker = World::getInstance().createAtom();
  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
  Walker->setType(hydrogen);
  Walker->setPosition(Vector(1., 1., 0. ));
  // construct fragment keyset
  SaturatedFragment::GlobalSaturationPositions_t globalpositions;
  set = new KeySet;
  set->insert(0);
  set->insert(1);
  set->insert(2);
  fragment = new SaturatedFragment(
      *set,
      KeySetsInUse,
      hydrogens,
      ExcludeHydrogen,
      DoSaturate,
      globalpositions);
}
void SaturatedFragmentTest::tearDown()
{
  delete fragment;
  delete set;
  // remove
  World::getInstance().destroyMolecule(TestMolecule);
  // note that all the atoms, molecules, the tafel and the elements
  // are all cleaned when the world is destroyed
  World::purgeInstance();
  AtomObserver::purgeInstance();
  logger::purgeInstance();
  errorLogger::purgeInstance();
  WorldTime::purgeInstance();
}
/** UnitTest for getKeySet()
 */
void SaturatedFragmentTest::getKeySet_Test()
{
  CPPUNIT_ASSERT_EQUAL( *set, fragment->getKeySet() );
}
/** UnitTest for getRoughBoundingBox()
 */
void SaturatedFragmentTest::getRoughBoundingBox()
{
  const std::pair minmax = fragment->getRoughBoundingBox();
  for (size_t i=0;i= 0. );
    CPPUNIT_ASSERT( minmax.second[i] <= 1. );
  }
}