Skip to content

Instantly share code, notes, and snippets.

@lshort
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lshort/e19cb74b5ffe0ff565e1 to your computer and use it in GitHub Desktop.
Save lshort/e19cb74b5ffe0ff565e1 to your computer and use it in GitHub Desktop.
Graph tests with expect_exception
void graph_tests(const digraph &g, digraph::nodename source,
digraph::nodename destination, const set<string> & except_on )
{
auto throw_return = [] ()
{ cout << "Caught Expected Exception" << endl; };
auto tst = [exc_return, except_on] (string fcn, auto a)
{
bool expect_throw = except_on.end()!=except_on.find(fcn);
auto normal_return = [fcn] (auto retval)
{ cout << fcn << " visiting " << retval << endl; };
expect_exception(a, expect_throw, throw_return, normal_return );
};
cout << endl << "=====> Beginning a test set" << endl;
tst("BFS", [g, source] () { return g.bfs(source); } );
tst("DFS", [g, source] () { return g.dfs(source); } );
tst("Topsort", [g] () { return g.topsort(); } );
tst("Dijkstra", [g, source, destination] ()
{ return g.dijkstra(source, destination); } );
tst("Bellman", [g, source] ()
{ return get<0>(g.bellman_ford(source).get()); } );
};
void main( )
{
// create the graphs x, y, z
set<string> none;
graph_tests(y,'A','D', none); // no algorithms will throw
graph_tests(z,'A','D', none); // no algorithms will throw
graph_tests(x,'A','D', set<string>{"Topsort"}); // topsort will throw
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment