- Better Makefile.am. (I hope.)
authoralpar
Thu, 22 Jul 2004 14:21:46 +0000
changeset 727aada518af30f
parent 726 835ebe1b3250
child 728 4c9e2f920458
- Better Makefile.am. (I hope.)
- Some more tests
src/test/Makefile.am
src/test/error_test.cc
src/test/test_tools_fail.cc
src/test/test_tools_pass.cc
src/test/xy_test.cc
     1.1 --- a/src/test/Makefile.am	Thu Jul 22 14:19:23 2004 +0000
     1.2 +++ b/src/test/Makefile.am	Thu Jul 22 14:21:46 2004 +0000
     1.3 @@ -1,10 +1,18 @@
     1.4  AM_CPPFLAGS = -I$(top_srcdir)/src
     1.5  
     1.6 -check_PROGRAMS = graph_test dijkstra_test time_measure_test 
     1.7 +noinst_HEADERS = test_tools.h
     1.8 +
     1.9 +check_PROGRAMS = graph_test dijkstra_test time_measure_test error_test xy_test \
    1.10 +	test_tools_pass test_tools_fail
    1.11  
    1.12  TESTS = $(check_PROGRAMS)
    1.13 -XFAIL_TESTS =
    1.14 +XFAIL_TESTS = test_tools_fail
    1.15  
    1.16 -graph_test_SOURCES = graph_test.cc test_tools.h
    1.17 -dijkstra_test_SOURCES = dijkstra_test.cc test_tools.h
    1.18 -time_measure_test_SOURCES = time_measure_test.cc
    1.19 \ No newline at end of file
    1.20 +graph_test_SOURCES = graph_test.cc
    1.21 +dijkstra_test_SOURCES = dijkstra_test.cc
    1.22 +time_measure_test_SOURCES = time_measure_test.cc
    1.23 +error_test_SOURCES = error_test.cc
    1.24 +xy_test_SOURCES = xy_test.cc
    1.25 +test_tools_pass_SOURCES = test_tools_pass.cc
    1.26 +test_tools_fail_SOURCES = test_tools_fail.cc
    1.27 +
     2.1 --- a/src/test/error_test.cc	Thu Jul 22 14:19:23 2004 +0000
     2.2 +++ b/src/test/error_test.cc	Thu Jul 22 14:21:46 2004 +0000
     2.3 @@ -1,7 +1,7 @@
     2.4  #include <iostream>
     2.5  
     2.6  #include <hugo/error.h>
     2.7 -
     2.8 +#include "test_tools.h"
     2.9  using namespace hugo;
    2.10  using std::cout;
    2.11  using std::endl;
    2.12 @@ -21,37 +21,29 @@
    2.13  
    2.14  
    2.15  int main() {
    2.16 -  bool no_errors = false;
    2.17 -
    2.18    try {
    2.19 -    cout << "Trying a faulty function\n";
    2.20      faulty_fn();
    2.21 -    no_errors = true;
    2.22 -    cout << "FAILED!\n";
    2.23 +    check(false, "A faulty function did not fail.");
    2.24    }
    2.25    catch(const Exception &e) {
    2.26 -    cout << "E: " << e.what() << endl;
    2.27 +    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    2.28    }
    2.29  
    2.30    try {
    2.31 -    cout << "Trying a function throwing Exception\n";
    2.32      exception_fn();
    2.33 -    no_errors = true;
    2.34 -    cout << "FAILED!\n";
    2.35 +    check(false, "The function did not throw Exception.");
    2.36    }
    2.37    catch(const Exception &e) {
    2.38 -    cout << "E: " << e.what() << endl;
    2.39 +    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    2.40    }
    2.41  
    2.42    try {
    2.43 -    cout << "Trying a function using FIXME\n";
    2.44      unfinished_fn();
    2.45 -    no_errors = true;
    2.46 -    cout << "FAILED!\n";
    2.47 +    check(false, "FIXME macro does not work.");
    2.48    }
    2.49    catch(const Exception &e) {
    2.50 -    cout << "E: " << e.what() << endl;
    2.51 +    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    2.52    }
    2.53  
    2.54 -  return no_errors ? 1 : 0;
    2.55 +  return 0;
    2.56  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/test/test_tools_fail.cc	Thu Jul 22 14:21:46 2004 +0000
     3.3 @@ -0,0 +1,7 @@
     3.4 +#include "test_tools.h"
     3.5 +
     3.6 +int main() 
     3.7 +{
     3.8 +  check(false, "Don't panic. Failing is the right behaviour.");
     3.9 +  return 0;
    3.10 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/test/test_tools_pass.cc	Thu Jul 22 14:21:46 2004 +0000
     4.3 @@ -0,0 +1,7 @@
     4.4 +#include "test_tools.h"
     4.5 +
     4.6 +int main() 
     4.7 +{
     4.8 +  check(true, "It should pass.");
     4.9 +  return 0;
    4.10 +}
     5.1 --- a/src/test/xy_test.cc	Thu Jul 22 14:19:23 2004 +0000
     5.2 +++ b/src/test/xy_test.cc	Thu Jul 22 14:21:46 2004 +0000
     5.3 @@ -1,21 +1,9 @@
     5.4  #include <hugo/xy.h>
     5.5  #include <iostream>
     5.6 +#include "test_tools.h"
     5.7 +
     5.8  using namespace std;
     5.9  using namespace hugo;
    5.10 -
    5.11 -bool passed = true;
    5.12 -
    5.13 -void check(bool rc, char *msg="") {
    5.14 -  passed = passed && rc;
    5.15 -  if(!rc) {
    5.16 -    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
    5.17 - 
    5.18 -
    5.19 -  }
    5.20 -}
    5.21 -
    5.22 -
    5.23 -
    5.24  int main()
    5.25  {
    5.26  
    5.27 @@ -28,12 +16,12 @@
    5.28  	XY b(3,4);
    5.29  
    5.30  	seged = a+b;
    5.31 -	check(seged.x==4 && seged.y==6);
    5.32 +	check(seged.x==4 && seged.y==6, "Wrong vector addition");
    5.33  
    5.34  	seged = a-b;
    5.35  	check(seged.x==-2 && seged.y==-2, "a-b");
    5.36  
    5.37 -	check(a.normSquare()==5);
    5.38 +	check(a.normSquare()==5,"Wrong norm calculation");
    5.39  	check(a*b==11, "a*b");
    5.40  
    5.41  	int l=2;
    5.42 @@ -58,23 +46,19 @@
    5.43  	      "added points to box");
    5.44  
    5.45  	seged.x=2;seged.y=3;
    5.46 -	check(doboz1.inside(seged),"Inside? Should be.");
    5.47 +	check(doboz1.inside(seged),"Inside? It should be.");
    5.48  
    5.49  	seged.x=1;seged.y=3;
    5.50 -	check(doboz1.inside(seged),"Inside? Should be.");
    5.51 +	check(doboz1.inside(seged),"Inside? It should be.");
    5.52  
    5.53  	seged.x=0;seged.y=3;
    5.54 -	check(!doboz1.inside(seged),"Inside? Should not be.");
    5.55 +	check(!doboz1.inside(seged),"Inside? It should not be.");
    5.56  
    5.57  	BB doboz2(seged);
    5.58 -	check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point.");
    5.59 +	check(!doboz2.empty(),
    5.60 +	      "empty? Should not be. Constructed from 1 point.");
    5.61  
    5.62  	doboz2 += doboz1;
    5.63 -	check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other.");
    5.64 -
    5.65 -	cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    5.66 -	     << endl;
    5.67 -
    5.68 -	return passed ? 0 : 1;
    5.69 -
    5.70 +	check(doboz2.inside(seged),
    5.71 +	      "Not inside? It should be. Incremented a box with an other.");
    5.72  }