From 817c277132c9de6cf976cea6d71abe375ccdd081 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sun, 17 Aug 2003 00:52:55 +0000 Subject: [PATCH] Added STL stack and vector tests. --- tests/Makefile | 0 tests/test_stack.cpp | 34 ++++++++++++++++++++++++++++++++++ tests/test_vector.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/Makefile create mode 100644 tests/test_stack.cpp create mode 100644 tests/test_vector.cpp diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_stack.cpp b/tests/test_stack.cpp new file mode 100644 index 0000000..ec6ebf8 --- /dev/null +++ b/tests/test_stack.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +int main(void) { + cout << "Pila comun..." << endl; + stack st; + st.push("Hola mundo"); + string s1 = "String 1"; + st.push(s1); + s1 += " "; + cout << "Primer elemento: " << st.top() << endl; + st.pop(); + cout << "Segundo elemento: " << st.top() << endl; + st.pop(); + cout << endl; + + cout << "Pila de punteros..." << endl; + stack stp; + string s = "Hola mundo"; + stp.push(&s); + //vp.push_back("Hola mundo"); + s1 = "String 1"; + stp.push(&s1); + s1 += " "; + while (!stp.empty()) { + cout << *(stp.top()) << endl; + stp.pop(); + } + return 0; +} + diff --git a/tests/test_vector.cpp b/tests/test_vector.cpp new file mode 100644 index 0000000..35b373f --- /dev/null +++ b/tests/test_vector.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace std; + +int main(void) { + cout << "Vector comun..." << endl; + vector v; + v.push_back("Hola mundo"); + string s1 = "String 1"; + v.push_back(s1); + s1 += " "; + for (vector::const_iterator i = v.begin(); i != v.end(); i++) { + cout << "Primer elemento: " << *i << endl; + } + cout << endl; + + cout << "Vector de punteros..." << endl; + vector vp; + string s = "Hola mundo"; + vp.push_back(&s); + //vp.push_back("Hola mundo"); + s1 = "String 1"; + vp.push_back(&s1); + s1 += " "; + for (vector::const_iterator i = vp.begin(); i != vp.end(); i++) { + cout << "Primer elemento: " << **i << endl; + } + return 0; +} + -- 2.43.0