From 782262feed25b87c7223883a3f86eb46ac89c9e7 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Thu, 29 Sep 2005 17:36:26 +0000 Subject: [PATCH] Test aleatoreo de Clave Variable. --- src/main_variable.cpp | 68 +++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main_variable.cpp b/src/main_variable.cpp index 9828e4e..477f632 100644 --- a/src/main_variable.cpp +++ b/src/main_variable.cpp @@ -2,6 +2,11 @@ #include "btree.h" #include "clave_variable.h" +#include +#include +#include + +void generar_aleatorio (std::list &lst, uint cant); int main (int argc, char *argv[]) { @@ -12,30 +17,63 @@ int main (int argc, char *argv[]) return 1; } - for (int i=0; i<=atoi(argv[1]); i++) { - std::stringstream ss; - std::string s; - ss << i; - ss >> s; - ClaveVariable c(s); + std::list lst; + generar_aleatorio (lst, atoi(argv[1])); + + std::list::iterator it = lst.begin (); + while (it != lst.end ()) { + ClaveVariable c(*it); - std::cout << "Agregando " << i << std::endl; + std::cout << "Agregando " << (*it) << std::endl; tree.AddKey (c); + it++; } - for (int i=0; i<=atoi(argv[1]); i++) { - std::stringstream ss; - std::string s; - ss << i; - ss >> s; - ClaveVariable c(s); + it = lst.begin (); + while (it != lst.end ()) { + ClaveVariable c(*it); if (tree.FindKey (c)) - std::cout << i << " encontrada\n"; + std::cout << (*it) << " encontrada\n"; else - std::cout << i << " NO encontrada\n"; + std::cout << (*it) << " NO encontrada\n"; + it++; } return 0; } +void get_file (const char *f, std::map &out, int &cant) +{ + std::ifstream reader (f); + cant = 0; + char l[100]; + + while (!reader.eof ()) { + reader.getline (l, 100); + out[cant] = std::string (l); + cant++; + } +} + + +void generar_aleatorio (std::list &lst, uint n) +{ + std::map productos; + std::map marcas; + int productos_cant, marcas_cant; + + get_file ("productos.txt", productos, productos_cant); + get_file ("marcas.txt", marcas, marcas_cant); + + srand (time (NULL)); + int random1, random2; + /* TODO : Evitar repetidos */ + for (uint i=0; i < n; i++) { + random1 = 1 + (int)(productos_cant * (float)rand () / (RAND_MAX + 1.0f)); + random2 = 1 + (int)(marcas_cant * (float)rand () / (RAND_MAX + 1.0f)); + + lst.push_back (productos[random1-1] + " " + marcas[random2-1]); + } +} + -- 2.43.0