source: src/Graph/unittests/BreadthFirstSearchGathererUnitTest.cpp@ 0dc8bf2

Action_Thermostats Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since 0dc8bf2 was 6e5b8d, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Added BreadthFirstSearchGathererUnitTest.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2017 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * BreadthFirstSearchGathererUnitTest.cpp
25 *
26 * Created on: May 19, 2017
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include <boost/assign.hpp>
42
43#include "CodePatterns/Log.hpp"
44
45#include "Graph/BoostGraphCreator.hpp"
46#include "Graph/BreadthFirstSearchGatherer.hpp"
47
48#include "BreadthFirstSearchGathererUnitTest.hpp"
49
50#ifdef HAVE_TESTRUNNER
51#include "UnitTestMain.hpp"
52#endif /*HAVE_TESTRUNNER*/
53
54using namespace boost::assign;
55
56/********************************************** Test classes **************************************/
57
58// Registers the fixture into the 'registry'
59CPPUNIT_TEST_SUITE_REGISTRATION( BreadthFirstSearchGathererTest );
60
61typedef std::pair<int,int> E;
62
63void BreadthFirstSearchGathererTest::setUp()
64{
65 BGCreator = new BoostGraphCreator();
66};
67
68
69void BreadthFirstSearchGathererTest::tearDown()
70{
71 delete BGCreator;
72};
73
74/** Little helper function to prepare a linear graph with vertices
75 * correctly named (not just indexed) and also the internal node
76 * map prepared.
77 */
78void BreadthFirstSearchGathererTest::prepareLinearGraph()
79{
80 E edges[] = { E(0,1), E(1,2), E(2,3), E(3,4) };
81 const size_t no_nodes = 5;
82 BGCreator->graph =
83 BoostGraphCreator::UndirectedGraph(edges, edges + sizeof(edges) / sizeof(E), no_nodes);
84 BGCreator->atomids_nodeids +=
85 make_pair(0,0), make_pair(1,1), make_pair(2,2), make_pair(3,3), make_pair(4,4);
86 for (size_t i=0;i<no_nodes;++i)
87 boost::put(boost::get(boost::vertex_name, BGCreator->graph), boost::vertex(i, BGCreator->graph), i+1);
88}
89
90/** Tests whether operator() works.
91 */
92void BreadthFirstSearchGathererTest::operatorTest()
93{
94 // create linear test graph
95 prepareLinearGraph();
96
97 // call operator with default argument
98 BreadthFirstSearchGatherer gatherer(*BGCreator);
99 std::vector<atomId_t> atomids = gatherer(0);
100
101 // create comparator set
102 std::vector<atomId_t> compareids;
103 compareids += 1,2,3,4,5;
104 CPPUNIT_ASSERT_EQUAL ((size_t)5, atomids.size());
105 CPPUNIT_ASSERT_EQUAL (compareids, atomids);
106};
Note: See TracBrowser for help on using the repository browser.