# HG changeset patch # User alpar # Date 1090506106 0 # Node ID aada518af30ff11e3fe971c1d78dc5435b591f9d # Parent 835ebe1b3250572ab331c463171bbe1533a08cad - Better Makefile.am. (I hope.) - Some more tests diff -r 835ebe1b3250 -r aada518af30f src/test/Makefile.am --- a/src/test/Makefile.am Thu Jul 22 14:19:23 2004 +0000 +++ b/src/test/Makefile.am Thu Jul 22 14:21:46 2004 +0000 @@ -1,10 +1,18 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -check_PROGRAMS = graph_test dijkstra_test time_measure_test +noinst_HEADERS = test_tools.h + +check_PROGRAMS = graph_test dijkstra_test time_measure_test error_test xy_test \ + test_tools_pass test_tools_fail TESTS = $(check_PROGRAMS) -XFAIL_TESTS = +XFAIL_TESTS = test_tools_fail -graph_test_SOURCES = graph_test.cc test_tools.h -dijkstra_test_SOURCES = dijkstra_test.cc test_tools.h -time_measure_test_SOURCES = time_measure_test.cc \ No newline at end of file +graph_test_SOURCES = graph_test.cc +dijkstra_test_SOURCES = dijkstra_test.cc +time_measure_test_SOURCES = time_measure_test.cc +error_test_SOURCES = error_test.cc +xy_test_SOURCES = xy_test.cc +test_tools_pass_SOURCES = test_tools_pass.cc +test_tools_fail_SOURCES = test_tools_fail.cc + diff -r 835ebe1b3250 -r aada518af30f src/test/error_test.cc --- a/src/test/error_test.cc Thu Jul 22 14:19:23 2004 +0000 +++ b/src/test/error_test.cc Thu Jul 22 14:21:46 2004 +0000 @@ -1,7 +1,7 @@ #include #include - +#include "test_tools.h" using namespace hugo; using std::cout; using std::endl; @@ -21,37 +21,29 @@ int main() { - bool no_errors = false; - try { - cout << "Trying a faulty function\n"; faulty_fn(); - no_errors = true; - cout << "FAILED!\n"; + check(false, "A faulty function did not fail."); } catch(const Exception &e) { - cout << "E: " << e.what() << endl; + cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl; } try { - cout << "Trying a function throwing Exception\n"; exception_fn(); - no_errors = true; - cout << "FAILED!\n"; + check(false, "The function did not throw Exception."); } catch(const Exception &e) { - cout << "E: " << e.what() << endl; + cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl; } try { - cout << "Trying a function using FIXME\n"; unfinished_fn(); - no_errors = true; - cout << "FAILED!\n"; + check(false, "FIXME macro does not work."); } catch(const Exception &e) { - cout << "E: " << e.what() << endl; + cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl; } - return no_errors ? 1 : 0; + return 0; } diff -r 835ebe1b3250 -r aada518af30f src/test/test_tools_fail.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/test_tools_fail.cc Thu Jul 22 14:21:46 2004 +0000 @@ -0,0 +1,7 @@ +#include "test_tools.h" + +int main() +{ + check(false, "Don't panic. Failing is the right behaviour."); + return 0; +} diff -r 835ebe1b3250 -r aada518af30f src/test/test_tools_pass.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/test_tools_pass.cc Thu Jul 22 14:21:46 2004 +0000 @@ -0,0 +1,7 @@ +#include "test_tools.h" + +int main() +{ + check(true, "It should pass."); + return 0; +} diff -r 835ebe1b3250 -r aada518af30f src/test/xy_test.cc --- a/src/test/xy_test.cc Thu Jul 22 14:19:23 2004 +0000 +++ b/src/test/xy_test.cc Thu Jul 22 14:21:46 2004 +0000 @@ -1,21 +1,9 @@ #include #include +#include "test_tools.h" + using namespace std; using namespace hugo; - -bool passed = true; - -void check(bool rc, char *msg="") { - passed = passed && rc; - if(!rc) { - std::cerr << "Test failed! ("<< msg << ")" << std::endl; \ - - - } -} - - - int main() { @@ -28,12 +16,12 @@ XY b(3,4); seged = a+b; - check(seged.x==4 && seged.y==6); + check(seged.x==4 && seged.y==6, "Wrong vector addition"); seged = a-b; check(seged.x==-2 && seged.y==-2, "a-b"); - check(a.normSquare()==5); + check(a.normSquare()==5,"Wrong norm calculation"); check(a*b==11, "a*b"); int l=2; @@ -58,23 +46,19 @@ "added points to box"); seged.x=2;seged.y=3; - check(doboz1.inside(seged),"Inside? Should be."); + check(doboz1.inside(seged),"Inside? It should be."); seged.x=1;seged.y=3; - check(doboz1.inside(seged),"Inside? Should be."); + check(doboz1.inside(seged),"Inside? It should be."); seged.x=0;seged.y=3; - check(!doboz1.inside(seged),"Inside? Should not be."); + check(!doboz1.inside(seged),"Inside? It should not be."); BB doboz2(seged); - check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point."); + check(!doboz2.empty(), + "empty? Should not be. Constructed from 1 point."); doboz2 += doboz1; - check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other."); - - cout << (passed ? "All tests passed." : "Some of the tests failed!!!") - << endl; - - return passed ? 0 : 1; - + check(doboz2.inside(seged), + "Not inside? It should be. Incremented a box with an other."); }