[Lemon-commits] [lemon_svn] alpar: r982 - hugo/trunk/src/test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:42:33 CET 2006


Author: alpar
Date: Thu Jul 22 16:21:46 2004
New Revision: 982

Added:
   hugo/trunk/src/test/test_tools_fail.cc
   hugo/trunk/src/test/test_tools_pass.cc
Modified:
   hugo/trunk/src/test/Makefile.am
   hugo/trunk/src/test/error_test.cc
   hugo/trunk/src/test/xy_test.cc

Log:
- Better Makefile.am. (I hope.)
- Some more tests



Modified: hugo/trunk/src/test/Makefile.am
==============================================================================
--- hugo/trunk/src/test/Makefile.am	(original)
+++ hugo/trunk/src/test/Makefile.am	Thu Jul 22 16:21:46 2004
@@ -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
+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
 
-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

Modified: hugo/trunk/src/test/error_test.cc
==============================================================================
--- hugo/trunk/src/test/error_test.cc	(original)
+++ hugo/trunk/src/test/error_test.cc	Thu Jul 22 16:21:46 2004
@@ -1,7 +1,7 @@
 #include <iostream>
 
 #include <hugo/error.h>
-
+#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;
 }

Added: hugo/trunk/src/test/test_tools_fail.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/test/test_tools_fail.cc	Thu Jul 22 16:21:46 2004
@@ -0,0 +1,7 @@
+#include "test_tools.h"
+
+int main() 
+{
+  check(false, "Don't panic. Failing is the right behaviour.");
+  return 0;
+}

Added: hugo/trunk/src/test/test_tools_pass.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/test/test_tools_pass.cc	Thu Jul 22 16:21:46 2004
@@ -0,0 +1,7 @@
+#include "test_tools.h"
+
+int main() 
+{
+  check(true, "It should pass.");
+  return 0;
+}

Modified: hugo/trunk/src/test/xy_test.cc
==============================================================================
--- hugo/trunk/src/test/xy_test.cc	(original)
+++ hugo/trunk/src/test/xy_test.cc	Thu Jul 22 16:21:46 2004
@@ -1,21 +1,9 @@
 #include <hugo/xy.h>
 #include <iostream>
+#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.");
 }



More information about the Lemon-commits mailing list