Last active
August 29, 2015 14:03
-
-
Save lshort/e19cb74b5ffe0ff565e1 to your computer and use it in GitHub Desktop.
Graph tests with expect_exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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