]> git.llucax.com Git - z.facultad/75.29/susanita.git/commitdiff
Agrega pruebas para la tabla hash y el heap.
authorLeandro Lucarella <luca@llucax.hn.org>
Mon, 7 Nov 2005 17:53:44 +0000 (17:53 +0000)
committerLeandro Lucarella <luca@llucax.hn.org>
Mon, 7 Nov 2005 17:53:44 +0000 (17:53 +0000)
test/Makefile [new file with mode: 0644]
test/hashtable_test.cpp [new file with mode: 0644]
test/heap_test.cpp [new file with mode: 0644]

diff --git a/test/Makefile b/test/Makefile
new file mode 100644 (file)
index 0000000..327f291
--- /dev/null
@@ -0,0 +1,30 @@
+
+# Opciones para el compilador C++.
+CXXFLAGS = -Wall -ansi -pedantic
+
+ifdef DEBUG
+CXXFLAGS += -ggdb -DDEBUG -fno-inline
+else
+CXXFLAGS += -O2 -DNDEBUG
+endif
+
+all: hashtable_test heap_test
+
+hashtable_test.o: ../src/persona.h ../src/hashtable.h hashtable_test.cpp
+
+hashtable_test: hashtable_test.o ../src/persona.o
+       $(CXX) $(LDFLAGS) hashtable_test.o ../src/persona.o $(LOADLIBES) $(LDLIBS) -o hashtable_test
+
+heap_test.o: ../src/heap.h heap_test.cpp
+
+heap_test: ../src/heap.h heap_test.o
+       $(CXX) $(LDFLAGS) heap_test.o $(LOADLIBES) $(LDLIBS) -o heap_test
+
+# REGLAS
+#########
+
+.PHONY: clean
+
+clean:
+       @$(RM) -fv *.o heap_test hashtable_test
+
diff --git a/test/hashtable_test.cpp b/test/hashtable_test.cpp
new file mode 100644 (file)
index 0000000..a04a8de
--- /dev/null
@@ -0,0 +1,26 @@
+#include "../src/hashtable.h"
+#include "../src/persona.h"
+#include <iostream>
+#include <stdexcept>
+
+int main()
+{
+       HashTable< Persona* > hash(20);
+       hash["luca"] = new Persona("luca", Persona::M, 20);
+       hash["alb"] = new Persona("albertito", Persona::M, 20);
+       hash["eze"] = new Persona("eze", Persona::M, 20);
+       std::cout << (*hash["luca"]) << "\n";
+       std::cout << (*hash["alb"]) << "\n";
+       std::cout << (*hash["eze"]) << "\n";
+       std::cout << hash["no_existo"] << "\n";
+       try
+       {
+               hash.get("menos_existo");
+       }
+       catch (std::exception& e)
+       {
+               std::cerr << e.what() << "\n";
+       }
+       return 0;
+}
+
diff --git a/test/heap_test.cpp b/test/heap_test.cpp
new file mode 100644 (file)
index 0000000..cc2c02c
--- /dev/null
@@ -0,0 +1,29 @@
+#include "../src/heap.h"
+#include <vector>
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+#include <functional>
+#include <cstdlib>
+
+
+int main(int argc, char* argv[])
+{
+       if (argc != 2)
+       {
+               std::cerr << "Uso: " << argv[0] << " cantidad\n";
+               return 1;
+       }
+       const int SIZE = atoi(argv[1]);
+       std::vector< int > v;
+       for (int i = 0; i < SIZE; ++i)
+       {
+               heap_push(v, rand() % (SIZE*10), std::less< int >());
+       }
+       for (int i = 0; i < SIZE; ++i)
+       {
+               std::cout << heap_pop(v, std::less< int >()) << "\n";
+       }
+       return 0;
+}
+