[Lemon-commits] Peter Kovacs: Improve and redesign test programs...
Lemon HG
hg at lemon.cs.elte.hu
Sun Jun 15 22:36:46 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/02f4d5d9bfd7
changeset: 171:02f4d5d9bfd7
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Sun Jun 15 22:05:23 2008 +0200
description:
Improve and redesign test programs + unify their output (ticket #25)
- Move graph related utilities form test_tools.h to graph_test.h.
- Move the contents of graph_utils_test.h to graph_utils_test.cc.
- Rename map_test.h -> graph_maps_test.h.
- Rename digraph_test.h -> graph_test.h.
- Many improvements in the following files:
* digraph_test.cc
* graph_test.cc
* graph_test.h
* graph_maps_test.h
* graph_utils_test.cc
* bfs_test.cc
* dfs_test.cc
* counter_test.cc
- Test programs print messages only if it really seems necessary.
- Remove \file commands form .cc test files.
diffstat:
22 files changed, 894 insertions(+), 966 deletions(-)
test/CMakeLists.txt | 3
test/Makefile.am | 5
test/bfs_test.cc | 56 +++------
test/counter_test.cc | 97 ++++++++++------
test/dfs_test.cc | 57 +++------
test/digraph_test.cc | 118 +++++++++++++++-----
test/digraph_test.h | 188 --------------------------------
test/dijkstra_test.cc | 4
test/dim_test.cc | 36 ++----
test/error_test.cc | 1
test/graph_maps_test.h | 144 ++++++++++++++++++++++++
test/graph_test.cc | 186 +++++++++++++------------------
test/graph_test.h | 262 +++++++++++++++++++++++++++++++++++++++++++++
test/graph_utils_test.cc | 248 +++++++++++++++++++++++++++---------------
test/graph_utils_test.h | 83 --------------
test/heap_test.cc | 11 -
test/kruskal_test.cc | 4
test/map_test.h | 149 -------------------------
test/random_test.cc | 5
test/test_tools.h | 152 +-------------------------
test/time_measure_test.cc | 5
test/unionfind_test.cc | 46 +++----
diffs (truncated from 2417 to 300 lines):
diff -r 91fb4372688f -r 02f4d5d9bfd7 test/CMakeLists.txt
--- a/test/CMakeLists.txt Sun Jun 15 22:03:33 2008 +0200
+++ b/test/CMakeLists.txt Sun Jun 15 22:05:23 2008 +0200
@@ -11,10 +11,11 @@
dim_test
error_test
graph_test
+ graph_utils_test
kruskal_test
maps_test
+ path_test
random_test
- path_test
time_measure_test
unionfind_test)
diff -r 91fb4372688f -r 02f4d5d9bfd7 test/Makefile.am
--- a/test/Makefile.am Sun Jun 15 22:03:33 2008 +0200
+++ b/test/Makefile.am Sun Jun 15 22:05:23 2008 +0200
@@ -2,10 +2,9 @@
test/CMakeLists.txt
noinst_HEADERS += \
- test/digraph_test.h \
- test/graph_utils_test.h \
+ test/graph_test.h \
test/heap_test.h \
- test/map_test.h \
+ test/graph_maps_test.h \
test/test_tools.h
check_PROGRAMS += \
diff -r 91fb4372688f -r 02f4d5d9bfd7 test/bfs_test.cc
--- a/test/bfs_test.cc Sun Jun 15 22:03:33 2008 +0200
+++ b/test/bfs_test.cc Sun Jun 15 22:05:23 2008 +0200
@@ -16,32 +16,25 @@
*
*/
-#include "test_tools.h"
-//#include <lemon/smart_graph.h>
+#include <lemon/concepts/digraph.h>
+#include <lemon/smart_graph.h>
#include <lemon/list_graph.h>
#include <lemon/bfs.h>
#include <lemon/path.h>
-#include<lemon/concepts/digraph.h>
+
+#include "graph_test.h"
+#include "test_tools.h"
using namespace lemon;
-const int PET_SIZE =5;
-
-
-void check_Bfs_Compile()
+void checkBfsCompile()
{
typedef concepts::Digraph Digraph;
-
- typedef Digraph::Arc Arc;
- typedef Digraph::Node Node;
- typedef Digraph::ArcIt ArcIt;
- typedef Digraph::NodeIt NodeIt;
-
typedef Bfs<Digraph> BType;
Digraph G;
- Node n;
- Arc e;
+ Digraph::Node n;
+ Digraph::Arc e;
int l;
bool b;
BType::DistMap d(G);
@@ -63,16 +56,12 @@
Path<Digraph> pp = bfs_test.path(n);
}
-void check_Bfs_Function_Compile()
+void checkBfsFunctionCompile()
{
typedef int VType;
typedef concepts::Digraph Digraph;
-
typedef Digraph::Arc Arc;
typedef Digraph::Node Node;
- typedef Digraph::ArcIt ArcIt;
- typedef Digraph::NodeIt NodeIt;
- typedef concepts::ReadMap<Arc,VType> LengthMap;
Digraph g;
bfs(g,Node()).run();
@@ -83,24 +72,15 @@
.reachedMap(concepts::ReadWriteMap<Node,bool>())
.processedMap(concepts::WriteMap<Node,bool>())
.run(Node());
-
}
-int main()
-{
-
- // typedef SmartDigraph Digraph;
- typedef ListDigraph Digraph;
-
- typedef Digraph::Arc Arc;
- typedef Digraph::Node Node;
- typedef Digraph::ArcIt ArcIt;
- typedef Digraph::NodeIt NodeIt;
- typedef Digraph::ArcMap<int> LengthMap;
+template <class Digraph>
+void checkBfs() {
+ TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
Digraph G;
Node s, t;
- PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
+ PetStruct<Digraph> ps = addPetersen(G, 5);
s=ps.outer[2];
t=ps.inner[0];
@@ -108,10 +88,10 @@
Bfs<Digraph> bfs_test(G);
bfs_test.run(s);
- check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t));
+ check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t));
Path<Digraph> p = bfs_test.path(t);
- check(p.length()==3,"getPath() found a wrong path.");
+ check(p.length()==3,"path() found a wrong path.");
check(checkPath(G, p),"path() found a wrong path.");
check(pathSource(G, p) == s,"path() found a wrong path.");
check(pathTarget(G, p) == t,"path() found a wrong path.");
@@ -139,3 +119,9 @@
}
}
+int main()
+{
+ checkBfs<ListDigraph>();
+ checkBfs<SmartDigraph>();
+ return 0;
+}
diff -r 91fb4372688f -r 02f4d5d9bfd7 test/counter_test.cc
--- a/test/counter_test.cc Sun Jun 15 22:03:33 2008 +0200
+++ b/test/counter_test.cc Sun Jun 15 22:05:23 2008 +0200
@@ -17,50 +17,75 @@
*/
#include <lemon/counter.h>
+#include <vector>
-///\file \brief Test cases for time_measure.h
-///
-///\todo To be extended
+using namespace lemon;
+template <typename T>
+void bubbleSort(std::vector<T>& v) {
+ Counter op("Bubble Sort - Operations: ");
+ Counter::NoSubCounter as(op, "Assignments: ");
+ Counter::NoSubCounter co(op, "Comparisons: ");
+ for (int i = v.size()-1; i > 0; --i) {
+ for (int j = 0; j < i; ++j) {
+ if (v[j] > v[j+1]) {
+ T tmp = v[j];
+ v[j] = v[j+1];
+ v[j+1] = tmp;
+ as += 3;
+ }
+ ++co;
+ }
+ }
+}
-int fibonacci(int f)
-{
- static lemon::Counter count("Fibonacci steps: ");
- count++;
- if(f<1) return 0;
- else if(f==1) return 1;
- else return fibonacci(f-1)+fibonacci(f-2);
+template <typename T>
+void insertionSort(std::vector<T>& v) {
+ Counter op("Insertion Sort - Operations: ");
+ Counter::NoSubCounter as(op, "Assignments: ");
+ Counter::NoSubCounter co(op, "Comparisons: ");
+ for (int i = 1; i < int(v.size()); ++i) {
+ T value = v[i];
+ ++as;
+ int j = i;
+ while (j > 0 && v[j-1] > value) {
+ v[j] = v[j-1];
+ --j;
+ ++co; ++as;
+ }
+ v[j] = value;
+ ++as;
+ }
+}
+
+template <typename MyCounter>
+void counterTest() {
+ MyCounter c("Main Counter: ");
+ c++;
+ typename MyCounter::SubCounter d(c, "SubCounter: ");
+ d++;
+ typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: ");
+ e++;
+ d+=3;
+ c-=4;
+ e-=2;
+ c.reset(2);
+ c.reset();
+}
+
+void init(std::vector<int>& v) {
+ v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100;
+ v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70;
}
int main()
{
- fibonacci(10);
+ counterTest<Counter>();
+ counterTest<NoCounter>();
- {
- typedef lemon::Counter MyCounter;
- MyCounter c("Main counter: ");
- c++;
- c++;
- MyCounter::SubCounter d(c,"Subcounter: ");
- d++;
- d++;
- MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: ");
- e++;
- e++;
- }
-
- {
- typedef lemon::NoCounter MyCounter;
- MyCounter c("Main counter: ");
- c++;
- c++;
- MyCounter::SubCounter d(c,"Subcounter: ");
- d++;
- d++;
- MyCounter::SubCounter::SubCounter e(d,"SubSubCounter: ");
- e++;
- e++;
- }
+ std::vector<int> x(10);
+ init(x); bubbleSort(x);
+ init(x); insertionSort(x);
return 0;
}
diff -r 91fb4372688f -r 02f4d5d9bfd7 test/dfs_test.cc
--- a/test/dfs_test.cc Sun Jun 15 22:03:33 2008 +0200
+++ b/test/dfs_test.cc Sun Jun 15 22:05:23 2008 +0200
@@ -16,32 +16,25 @@
*
*/
-#include "test_tools.h"
-// #include <lemon/smart_graph.h>
+#include <lemon/concepts/digraph.h>
+#include <lemon/smart_graph.h>
#include <lemon/list_graph.h>
#include <lemon/dfs.h>
#include <lemon/path.h>
-#include <lemon/concepts/digraph.h>
+
+#include "graph_test.h"
+#include "test_tools.h"
using namespace lemon;
-const int PET_SIZE =5;
-
-
-void check_Dfs_SmartDigraph_Compile()
+void checkDfsCompile()
{
typedef concepts::Digraph Digraph;
-
- typedef Digraph::Arc Arc;
- typedef Digraph::Node Node;
- typedef Digraph::ArcIt ArcIt;
- typedef Digraph::NodeIt NodeIt;
-
typedef Dfs<Digraph> DType;
Digraph G;
- Node n;
- Arc e;
More information about the Lemon-commits
mailing list