From 47865f45f411d162cadf92859a89e32cc5e64681 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 7 Nov 2005 17:53:44 +0000 Subject: [PATCH] Agrega pruebas para la tabla hash y el heap. --- test/Makefile | 30 ++++++++++++++++++++++++++++++ test/hashtable_test.cpp | 26 ++++++++++++++++++++++++++ test/heap_test.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 test/Makefile create mode 100644 test/hashtable_test.cpp create mode 100644 test/heap_test.cpp diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..327f291 --- /dev/null +++ b/test/Makefile @@ -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 index 0000000..a04a8de --- /dev/null +++ b/test/hashtable_test.cpp @@ -0,0 +1,26 @@ +#include "../src/hashtable.h" +#include "../src/persona.h" +#include +#include + +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 index 0000000..cc2c02c --- /dev/null +++ b/test/heap_test.cpp @@ -0,0 +1,29 @@ +#include "../src/heap.h" +#include +#include +#include +#include +#include +#include + + +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; +} + -- 2.43.0