Ignore:
Timestamp:
May 19, 2017, 1:13:41 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_goodresults, ForceAnnealing_tocheck
Children:
53ef16e
Parents:
adbeca
Message:

Edges may be added and removed in BoostGraphCreator.

  • TESTS: added unit test case on this.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/unittests/BoostGraphCreatorUnitTest.cpp

    radbeca r94791a  
    172172  CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumEdges());
    173173};
     174
     175/** Tests whether adding and removing edges works.
     176 */
     177void BoostGraphCreatorTest::addremoveEdgeTest()
     178{
     179  typedef std::pair<int,int> E;
     180
     181  E edges[] = { E(0,1), E(1,2), E(2,3), E(3,4) };
     182  const size_t no_nodes = 5;
     183  BGCreator->graph =
     184      BoostGraphCreator::UndirectedGraph(edges, edges + sizeof(edges) / sizeof(E), no_nodes);
     185  BGCreator->atomids_nodeids +=
     186      make_pair(0,0), make_pair(1,1), make_pair(2,2), make_pair(3,3), make_pair(4,4);
     187  for (size_t i=0;i<no_nodes;++i)
     188    boost::put(boost::get(boost::vertex_name, BGCreator->graph), boost::vertex(i, BGCreator->graph), i);
     189
     190  CPPUNIT_ASSERT_EQUAL ((size_t)5, BGCreator->getNumVertices());
     191  CPPUNIT_ASSERT_EQUAL ((size_t)4, BGCreator->getNumEdges());
     192
     193  bool status;
     194  // remove a valid edge
     195  {
     196    status = BGCreator->removeEdge((atomId_t)0,(atomId_t)1);
     197    CPPUNIT_ASSERT_EQUAL (true, status);
     198    status = BGCreator->addEdge((atomId_t)0,(atomId_t)1);
     199    CPPUNIT_ASSERT_EQUAL (true, status);
     200    // check again whether edge has really been added again
     201    status = BGCreator->removeEdge((atomId_t)0,(atomId_t)1);
     202    CPPUNIT_ASSERT_EQUAL (true, status);
     203    status = BGCreator->addEdge((atomId_t)0,(atomId_t)1);
     204    CPPUNIT_ASSERT_EQUAL (true, status);
     205  }
     206
     207  // remove an invalid edge
     208  {
     209    status = BGCreator->removeEdge((atomId_t)0,(atomId_t)2);
     210    CPPUNIT_ASSERT_EQUAL (false, status);
     211  }
     212
     213  // add a present edge
     214  {
     215    status = BGCreator->addEdge((atomId_t)0,(atomId_t)1);
     216    CPPUNIT_ASSERT_EQUAL (false, status);
     217  }
     218};
Note: See TracChangeset for help on using the changeset viewer.