diff --git a/librerie/Ferro-Alessandro-N86002853(Esercizio1).zip b/librerie/Ferro-Alessandro-N86002853(Esercizio1).zip deleted file mode 100644 index 983b088..0000000 Binary files a/librerie/Ferro-Alessandro-N86002853(Esercizio1).zip and /dev/null differ diff --git a/librerie/exercise2/Exercise2.pdf b/librerie/exercise2/Exercise2.pdf new file mode 100755 index 0000000..6c07004 Binary files /dev/null and b/librerie/exercise2/Exercise2.pdf differ diff --git a/librerie/exercise2/build.sh b/librerie/exercise2/build.sh new file mode 100755 index 0000000..a7df24e --- /dev/null +++ b/librerie/exercise2/build.sh @@ -0,0 +1,8 @@ + +#! /bin/bash + +g++ -O3 -o main \ + zlasdtest/exercise1/simpletest.cpp zlasdtest/exercise1/fulltest.cpp \ + zlasdtest/exercise2/simpletest.cpp zlasdtest/exercise2/fulltest.cpp \ + zlasdtest/container/container.cpp \ + zlasdtest/test.cpp main.cpp diff --git a/librerie/exercise2/container/container.cpp b/librerie/exercise2/container/container.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/container/container.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/container/container.hpp b/librerie/exercise2/container/container.hpp new file mode 100755 index 0000000..c7c268a --- /dev/null +++ b/librerie/exercise2/container/container.hpp @@ -0,0 +1,318 @@ + +#ifndef CONTAINER_HPP +#define CONTAINER_HPP + +/* ************************************************************************** */ + +#include +#include + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +class Container { + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~Container() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // type Empty() specifiers; // (concrete function should not throw exceptions) + + // type Size() specifiers; // (concrete function should not throw exceptions) + + // type Clear() specifiers; + +}; + +/* ************************************************************************** */ + +template +class LinearContainer { // Must extend Container + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~LinearContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // type Front() specifiers; // (concrete function must throw std::length_error when empty) + // type Back() specifiers; // (concrete function must throw std::length_error when empty) + + // type operator[](argument) specifiers; // (concrete function must throw std::out_of_range when out of range) + +}; + +/* ************************************************************************** */ + +template +class TestableContainer { // Must extend Container + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~TestableContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // type Exists(argument) specifiers; // (concrete function should not throw exceptions) + +}; + +/* ************************************************************************** */ + +template +class MappableContainer { // Must extend Container + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~MappableContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // typedef std::function MapFunctor; + + // type MapPreOrder(arguments) specifiers; + // type MapPostOrder(arguments) specifiers; + +}; + +/* ************************************************************************** */ + +template +class FoldableContainer { // Must extend TestableContainer + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~FoldableContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // typedef std::function FoldFunctor; + + // type FoldPreOrder(arguments) specifiers; + // type FoldPostOrder(arguments) specifiers; + + // type Exists(argument) specifiers; // Override TestableContainer member + +}; + +/* ************************************************************************** */ + +template +class BreadthMappableContainer { // Must extend MappableContainer + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~BreadthMappableContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // using typename MappableContainer::MapFunctor; + + // type MapBreadth(arguments) specifiers; + +}; + +/* ************************************************************************** */ + +template +class BreadthFoldableContainer { // Must extend FoldableContainer + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~BreadthFoldableContainer() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // using typename FoldableContainer::FoldFunctor; + + // type FoldBreadth(arguments) specifiers; + +}; + +/* ************************************************************************** */ + +} + +#include "container.cpp" + +#endif diff --git a/librerie/exercise2/list/list.cpp b/librerie/exercise2/list/list.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/list/list.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/list/list.hpp b/librerie/exercise2/list/list.hpp new file mode 100755 index 0000000..c80e4df --- /dev/null +++ b/librerie/exercise2/list/list.hpp @@ -0,0 +1,169 @@ + +#ifndef LIST_HPP +#define LIST_HPP + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class List { // Must extend LinearContainer, MappableContainer, and FoldableContainer + +private: + + // ... + +protected: + + // using LinearContainer::???; + + struct Node + { + + // Data + // ... + + /* ********************************************************************** */ + + // Specific constructors + // ... + + /* ********************************************************************** */ + + // Copy constructor + // ... + + // Move constructor + // ... + + /* ********************************************************************** */ + + // Destructor + // ... + + /* ********************************************************************** */ + + // Comparison operators + // ... + + /* ********************************************************************** */ + + // Specific member functions + + // ... + + }; + + // ... + +public: + + // Default constructor + // List() specifiers; + + /* ************************************************************************ */ + + // Specific constructor + // List(argument) specifiers; // A list obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // List(argument) specifiers; + + // Move constructor + // List(argument) specifiers; + + /* ************************************************************************ */ + + // Destructor + // ~List() specifiers; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument) specifiers; + + // Move assignment + // type operator=(argument) specifiers; + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions + + // type InsertAtFront(argument) specifier; // Copy of the value + // type InsertAtFront(argument) specifier; // Move of the value + // type RemoveFromFront() specifier; // (must throw std::length_error when empty) + // type FrontNRemove() specifier; // (must throw std::length_error when empty) + + // type InsertAtBack(argument) specifier; // Copy of the value + // type InsertAtBack(argument) specifier; // Move of the value + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Clear() specifiers; // Override Container member + + /* ************************************************************************ */ + + // Specific member functions (inherited from LinearContainer) + + // type Front() specifiers; // Override LinearContainer member (must throw std::length_error when empty) + // type Back() specifiers; // Override LinearContainer member (must throw std::length_error when empty) + + // type operator[](argument) specifiers; // Override LinearContainer member (must throw std::out_of_range when out of range) + + /* ************************************************************************ */ + + // Specific member functions (inherited from MappableContainer) + + // using typename MappableContainer::MapFunctor; + + // type MapPreOrder(arguments) specifiers; // Override MappableContainer member + // type MapPostOrder(arguments) specifiers; // Override MappableContainer member + + /* ************************************************************************ */ + + // Specific member functions (inherited from FoldableContainer) + + // using typename FoldableContainer::FoldFunctor; + + // type FoldPreOrder(arguments) specifiers; // Override FoldableContainer member + // type FoldPostOrder(arguments) specifiers; // Override FoldableContainer member + +protected: + + // Auxiliary member functions (for MappableContainer) + + // type MapPreOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards + // type MapPostOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards + + /* ************************************************************************ */ + + // Auxiliary member functions (for FoldableContainer) + + // type FoldPreOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards + // type FoldPostOrder(arguments) specifiers; // Accessory function executing from one point of the list onwards + +}; + +/* ************************************************************************** */ + +} + +#include "list.cpp" + +#endif diff --git a/librerie/exercise2/main.cpp b/librerie/exercise2/main.cpp new file mode 100755 index 0000000..34faa12 --- /dev/null +++ b/librerie/exercise2/main.cpp @@ -0,0 +1,16 @@ + +#include "zlasdtest/test.hpp" + +#include "zmytest/test.hpp" + +/* ************************************************************************** */ + +#include + +/* ************************************************************************** */ + +int main() { + std::cout << "Lasd Libraries 2020" << std::endl; + lasdtest(); // To call in the menu of your library test! + return 0; +} diff --git a/librerie/exercise2/queue/lst/queuelst.cpp b/librerie/exercise2/queue/lst/queuelst.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/queue/lst/queuelst.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/queue/lst/queuelst.hpp b/librerie/exercise2/queue/lst/queuelst.hpp new file mode 100755 index 0000000..4f1954c --- /dev/null +++ b/librerie/exercise2/queue/lst/queuelst.hpp @@ -0,0 +1,90 @@ + +#ifndef QUEUELST_HPP +#define QUEUELST_HPP + +/* ************************************************************************** */ + +#include "../queue.hpp" +#include "../../list/list.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class QueueLst { // Must extend Queue and List + +private: + + // ... + +protected: + + // using List::???; + + // ... + +public: + + // Default constructor + // QueueLst() specifier; + + /* ************************************************************************ */ + + // Specific constructor + // QueueLst(argument) specifiers; // A queue obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // QueueLst(argument); + + // Move constructor + // QueueLst(argument); + + /* ************************************************************************ */ + + // Destructor + // ~QueueLst() specifier; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); + + // Move assignment + // type operator=(argument); + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions (inherited from Queue) + + // type Enqueue(argument) specifiers; // Override Queue member (copy of the value) + // type Enqueue(argument) specifiers; // Override Queue member (move of the value) + // type Head() specifiers; // Override Queue member (must throw std::length_error when empty) + // type Dequeue() specifiers; // Override Queue member (must throw std::length_error when empty) + // type HeadNDequeue() specifiers; // Override Queue member (must throw std::length_error when empty) + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Clear() specifiers; // Override Container member + +}; + +/* ************************************************************************** */ + +} + +#include "queuelst.cpp" + +#endif diff --git a/librerie/exercise2/queue/queue.hpp b/librerie/exercise2/queue/queue.hpp new file mode 100755 index 0000000..6b612e4 --- /dev/null +++ b/librerie/exercise2/queue/queue.hpp @@ -0,0 +1,61 @@ + +#ifndef QUEUE_HPP +#define QUEUE_HPP + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class Queue { // Must extend Container + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~Queue() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // type Enqueue(argument) specifiers; // Copy of the value + // type Enqueue(argument) specifiers; // Move of the value + // type Head() specifiers; // (concrete function must throw std::length_error when empty) + // type Dequeue() specifiers; // (concrete function must throw std::length_error when empty) + // type HeadNDequeue() specifiers; // (concrete function must throw std::length_error when empty) + +}; + +/* ************************************************************************** */ + +} + +#endif diff --git a/librerie/exercise2/queue/vec/queuevec.cpp b/librerie/exercise2/queue/vec/queuevec.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/queue/vec/queuevec.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/queue/vec/queuevec.hpp b/librerie/exercise2/queue/vec/queuevec.hpp new file mode 100755 index 0000000..97b7e97 --- /dev/null +++ b/librerie/exercise2/queue/vec/queuevec.hpp @@ -0,0 +1,102 @@ + +#ifndef QUEUEVEC_HPP +#define QUEUEVEC_HPP + +/* ************************************************************************** */ + +#include "../queue.hpp" +#include "../../vector/vector.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class QueueVec { // Must extend Queue and Vector + +private: + + // ... + +protected: + + // using Vector::???; + + // ... + +public: + + // Default constructor + // QueueVec() specifier; + + /* ************************************************************************ */ + + // Specific constructor + // QueueVec(argument) specifiers; // A queue obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // QueueVec(argument); + + // Move constructor + // QueueVec(argument); + + /* ************************************************************************ */ + + // Destructor + // ~QueueVec() specifier; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); + + // Move assignment + // type operator=(argument); + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions (inherited from Queue) + + // type Enqueue(argument) specifiers; // Override Queue member (copy of the value) + // type Enqueue(argument) specifiers; // Override Queue member (move of the value) + // type Head() specifiers; // Override Queue member (must throw std::length_error when empty) + // type Dequeue() specifiers; // Override Queue member (must throw std::length_error when empty) + // type HeadNDequeue() specifiers; // Override Queue member (must throw std::length_error when empty) + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Empty() specifiers; // Override Container member + + // type Size() specifiers; // Override Container member + + // type Clear() specifiers; // Override Container member + +protected: + + // Auxiliary member functions + + // type Expand() specifiers; + // type Reduce() specifiers; + // type SwapVectors(arguments) specifiers; + +}; + +/* ************************************************************************** */ + +} + +#include "queuevec.cpp" + +#endif diff --git a/librerie/exercise2/stack/lst/stacklst.cpp b/librerie/exercise2/stack/lst/stacklst.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/stack/lst/stacklst.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/stack/lst/stacklst.hpp b/librerie/exercise2/stack/lst/stacklst.hpp new file mode 100755 index 0000000..67fbb32 --- /dev/null +++ b/librerie/exercise2/stack/lst/stacklst.hpp @@ -0,0 +1,90 @@ + +#ifndef STACKLST_HPP +#define STACKLST_HPP + +/* ************************************************************************** */ + +#include "../stack.hpp" +#include "../../list/list.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class StackLst { // Must extend Stack and List + +private: + + // ... + +protected: + + // using List::???; + + // ... + +public: + + // Default constructor + // StackLst() specifier; + + /* ************************************************************************ */ + + // Specific constructor + // StackLst(argument) specifiers; // A stack obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // StackLst(argument); + + // Move constructor + // StackLst(argument); + + /* ************************************************************************ */ + + // Destructor + // ~StackLst() specifier; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); + + // Move assignment + // type operator=(argument); + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions (inherited from Stack) + + // type Push(argument) specifiers; // Override Stack member (copy of the value) + // type Push(argument) specifiers; // Override Stack member (move of the value) + // type Top() specifiers; // Override Stack member (must throw std::length_error when empty) + // type Pop() specifiers; // Override Stack member (must throw std::length_error when empty) + // type TopNPop() specifiers; // Override Stack member (must throw std::length_error when empty) + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Clear() specifiers; // Override Container member + +}; + +/* ************************************************************************** */ + +} + +#include "stacklst.cpp" + +#endif diff --git a/librerie/exercise2/stack/stack.hpp b/librerie/exercise2/stack/stack.hpp new file mode 100755 index 0000000..73a3a7c --- /dev/null +++ b/librerie/exercise2/stack/stack.hpp @@ -0,0 +1,61 @@ + +#ifndef STACK_HPP +#define STACK_HPP + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class Stack { // Must extend Container + +private: + + // ... + +protected: + + // ... + +public: + + // Destructor + // ~Stack() specifiers + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); // Copy assignment of abstract types should not be possible. + + // Move assignment + // type operator=(argument); // Move assignment of abstract types should not be possible. + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; // Comparison of abstract types might not be possible. + // type operator!=(argument) specifiers; // Comparison of abstract types might not be possible. + + /* ************************************************************************ */ + + // Specific member functions + + // type Push(argument) specifiers; // Copy of the value + // type Push(argument) specifiers; // Move of the value + // type Top() specifiers; // (concrete function must throw std::length_error when empty) + // type Pop() specifiers; // (concrete function must throw std::length_error when empty) + // type TopNPop() specifiers; // (concrete function must throw std::length_error when empty) + +}; + +/* ************************************************************************** */ + +} + +#endif diff --git a/librerie/exercise2/stack/vec/stackvec.cpp b/librerie/exercise2/stack/vec/stackvec.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/stack/vec/stackvec.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/stack/vec/stackvec.hpp b/librerie/exercise2/stack/vec/stackvec.hpp new file mode 100755 index 0000000..5e65367 --- /dev/null +++ b/librerie/exercise2/stack/vec/stackvec.hpp @@ -0,0 +1,101 @@ + +#ifndef STACKVEC_HPP +#define STACKVEC_HPP + +/* ************************************************************************** */ + +#include "../stack.hpp" +#include "../../vector/vector.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class StackVec { // Must extend Stack and Vector + +private: + + // ... + +protected: + + // using Vector::???; + + // ... + +public: + + // Default constructor + // StackVec() specifier; + + /* ************************************************************************ */ + + // Specific constructor + // StackVec(argument) specifiers; // A stack obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // StackVec(argument); + + // Move constructor + // StackVec(argument); + + /* ************************************************************************ */ + + // Destructor + // ~StackVec() specifier; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument); + + // Move assignment + // type operator=(argument); + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions (inherited from Stack) + + // type Push(argument) specifiers; // Override Stack member (copy of the value) + // type Push(argument) specifiers; // Override Stack member (move of the value) + // type Top() specifiers; // Override Stack member (must throw std::length_error when empty) + // type Pop() specifiers; // Override Stack member (must throw std::length_error when empty) + // type TopNPop() specifiers; // Override Stack member (must throw std::length_error when empty) + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Empty() specifiers; // Override Container member + + // type Size() specifiers; // Override Container member + + // type Clear() specifiers; // Override Container member + +protected: + + // Auxiliary member functions + + // type Expand() specifiers; + // type Reduce() specifiers; + +}; + +/* ************************************************************************** */ + +} + +#include "stackvec.cpp" + +#endif diff --git a/librerie/exercise2/vector/vector.cpp b/librerie/exercise2/vector/vector.cpp new file mode 100755 index 0000000..d374ceb --- /dev/null +++ b/librerie/exercise2/vector/vector.cpp @@ -0,0 +1,10 @@ + +namespace lasd { + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +} diff --git a/librerie/exercise2/vector/vector.hpp b/librerie/exercise2/vector/vector.hpp new file mode 100755 index 0000000..6f127ff --- /dev/null +++ b/librerie/exercise2/vector/vector.hpp @@ -0,0 +1,113 @@ + +#ifndef VECTOR_HPP +#define VECTOR_HPP + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +/* ************************************************************************** */ + +namespace lasd { + +/* ************************************************************************** */ + +template +class Vector { // Must extend LinearContainer, MappableContainer, and FoldableContainer + +private: + + // ... + +protected: + + // using LinearContainer::???; + + // ... + +public: + + // Default constructor + // Vector() specifiers; + + /* ************************************************************************ */ + + // Specific constructors + // Vector(argument) specifiers; // A vector with a given initial dimension + // Vector(argument) specifiers; // A vector obtained from a LinearContainer + + /* ************************************************************************ */ + + // Copy constructor + // Vector(argument) specifiers; + + // Move constructor + // Vector(argument) specifiers; + + /* ************************************************************************ */ + + // Destructor + // ~Vector() specifiers; + + /* ************************************************************************ */ + + // Copy assignment + // type operator=(argument) specifiers; + + // Move assignment + // type operator=(argument) specifiers; + + /* ************************************************************************ */ + + // Comparison operators + // type operator==(argument) specifiers; + // type operator!=(argument) specifiers; + + /* ************************************************************************ */ + + // Specific member functions + + // type Resize(argument) specifiers; // Resize the vector to a given size + + /* ************************************************************************ */ + + // Specific member functions (inherited from Container) + + // type Clear() specifiers; // Override Container member + + /* ************************************************************************ */ + + // Specific member functions (inherited from LinearContainer) + + // type Front() specifiers; // Override LinearContainer member (must throw std::length_error when empty) + // type Back() specifiers; // Override LinearContainer member (must throw std::length_error when empty) + + // type operator[](argument) specifiers; // Override LinearContainer member (must throw std::out_of_range when out of range) + + /* ************************************************************************ */ + + // Specific member functions (inherited from MappableContainer) + + // using typename MappableContainer::MapFunctor; + + // type MapPreOrder(arguments) specifiers; // Override MappableContainer member + // type MapPostOrder(arguments) specifiers; // Override MappableContainer member + + /* ************************************************************************ */ + + // Specific member functions (inherited from FoldableContainer) + + // using typename FoldableContainer::FoldFunctor; + + // type FoldPreOrder(arguments) specifiers; // Override FoldableContainer member + // type FoldPostOrder(arguments) specifiers; // Override FoldableContainer member + +}; + +/* ************************************************************************** */ + +} + +#include "vector.cpp" + +#endif diff --git a/librerie/exercise2/zlasdtest/container/container.cpp b/librerie/exercise2/zlasdtest/container/container.cpp new file mode 100755 index 0000000..0f37c81 --- /dev/null +++ b/librerie/exercise2/zlasdtest/container/container.cpp @@ -0,0 +1,49 @@ + +#include + +/* ************************************************************************** */ + +#include "../../container/container.hpp" + +/* ************************************************************************** */ + +// Container member functions! + +void Empty(uint& testnum, uint& testerr, const lasd::Container& con, bool chk) { + bool tst; + testnum++; + std::cout << " " << testnum << " The container is " << ((tst = con.Empty()) ? "" : "not ") << "empty: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + testerr += (1 - (uint) tst); +} + +void Size(uint& testnum, uint& testerr, const lasd::Container& con, bool chk, ulong siz) { + bool tst; + testnum++; + std::cout << " " << testnum << " The container has size " << con.Size() << ": "; + std::cout << ((tst = ((con.Size() == siz) == chk)) ? "Correct" : "Error") << "!" << std::endl; + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +// Auxiliary functions for MappableContainer! + +void MapStringAppend(std::string& dat, void* par) { + dat.append(*((std::string*) par)); +} + +/* ************************************************************************** */ + +// Auxiliary functions for FoldableContainer! + +void FoldParity(const int& dat, const void* _, void* acc) { + *((int*) acc) += dat; + *((int*) acc) %= 2; +} + +void FoldStringConcatenate(const std::string& dat, const void* _, void* acc) { + ((std::string*) acc)->append(dat); +} + +/* ************************************************************************** */ diff --git a/librerie/exercise2/zlasdtest/container/container.hpp b/librerie/exercise2/zlasdtest/container/container.hpp new file mode 100755 index 0000000..d1503cc --- /dev/null +++ b/librerie/exercise2/zlasdtest/container/container.hpp @@ -0,0 +1,301 @@ + +#ifndef CONTAINERTEST_HPP +#define CONTAINERTEST_HPP + +#include "../../container/container.hpp" + +/* ************************************************************************** */ + +// Container member functions! + +void Empty(uint&, uint&, const lasd::Container&, bool); + +void Size(uint&, uint&, const lasd::Container&, bool, ulong); + +/* ************************************************************************** */ + +// LinearContainer member functions! + +template +void GetFront(uint& testnum, uint& testerr, const lasd::LinearContainer& con, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The front of the linear container is \"" << con.Front() << "\": "; + std::cout << ((tst = ((con.Front() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void SetFront(uint& testnum, uint& testerr, const lasd::LinearContainer& con, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Setting the front of the linear container to \"" << val << "\": "; + con.Front() = val; + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void GetBack(uint& testnum, uint& testerr, const lasd::LinearContainer& con, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The back of the linear container is \"" << con.Back() << "\": "; + std::cout << ((tst = ((con.Back() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void SetBack(uint& testnum, uint& testerr, const lasd::LinearContainer& con, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Setting the back of the linear container to \"" << val << "\": "; + con.Back() = val; + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void SetAt(uint& testnum, uint& testerr, lasd::LinearContainer& con, bool chk, const ulong& ind, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Set of the linear container at index \"" << ind << "\" with value \"" << val << "\": "; + con[ind] = val; + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::out_of_range exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer& con, bool chk, const ulong& ind, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Get of the linear container at index \"" << ind << "\" with value \"" << con[ind] << "\": "; + std::cout << ((tst = ((con[ind] == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::out_of_range exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +// TestableContainer member functions! + +template +void Exists(uint& testnum, uint& testerr, const lasd::TestableContainer& con, bool chk, const Data& val) { + bool tst; + testnum++; + std::cout << " " << testnum << " Data \"" << val << "\" " << ((tst = con.Exists(val)) ? "does" : "does not") << " exist: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +// MappableContainer member functions! + +template +void MapPreOrder(uint& testnum, uint& testerr, lasd::MappableContainer& con, bool chk, typename lasd::MappableContainer::MapFunctor fun, const Parameter& inipar) { + bool tst = true; + testnum++; + Parameter par = {inipar}; + try { + std::cout << " " << testnum << " Executing map in pre order - "; + con.MapPreOrder(fun, &par); + std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void MapPostOrder(uint& testnum, uint& testerr, lasd::MappableContainer& con, bool chk, typename lasd::MappableContainer::MapFunctor fun, const Parameter& inipar) { + bool tst = true; + testnum++; + Parameter par = {inipar}; + try { + std::cout << " " << testnum << " Executing map in post order - "; + con.MapPostOrder(fun, &par); + std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void MapPrint(const Data& dat, void* _) { + std::cout << dat << " "; +} + +template +void MapIncrement(Data& dat, void* _) { + dat++; +} + +template +void MapIncrementNPrint(Data& dat, void* _) { + std::cout << dat++ << "->" << dat << "; "; +} + +template +void MapDouble(Data& dat, void* _) { + dat *= 2; +} + +template +void MapDoubleNPrint(Data& dat, void* _) { + std::cout << dat << "->" << (dat *= 2) << "; "; +} + +template +void MapInvert(Data& dat, void* _) { + dat = -dat; +} + +template +void MapInvertNPrint(Data& dat, void* _) { + std::cout << dat << "->" << (dat = -dat) << "; "; +} + +template +void MapParityInvert(Data& dat, void* _) { + if (dat % 2 != 0) { dat = -dat; } +} + +void MapStringAppend(std::string&, void*); + +/* ************************************************************************** */ + +// FoldableContainer member functions! + +template +void FoldPreOrder(uint& testnum, uint& testerr, const lasd::FoldableContainer& con, bool chk, typename lasd::FoldableContainer::FoldFunctor fun, const Parameter& inipar, const Value& inival, const Value& finval) { + bool tst; + testnum++; + Parameter par = {inipar}; + Value val = inival; + try { + std::cout << " " << testnum << " Executing fold in pre order - "; + con.FoldPreOrder(fun, &par, &val); + std::cout << "obtained value is \"" << val << "\": "; + std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void FoldPostOrder(uint& testnum, uint& testerr, const lasd::FoldableContainer& con, bool chk, typename lasd::FoldableContainer::FoldFunctor fun, const Parameter& inipar, const Value& inival, const Value& finval) { + bool tst; + testnum++; + Parameter par = {inipar}; + Value val = inival; + try { + std::cout << " " << testnum << " Executing fold in post order - "; + con.FoldPostOrder(fun, &par, &val); + std::cout << "obtained value is \"" << val << "\": "; + std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void FoldAdd(const Data& dat, const void* _, void* acc) { + *((Data*) acc) += dat; +} + +template +void FoldMultiply(const Data& dat, const void* _, void* acc) { + *((Data*) acc) *= dat; +} + +void FoldParity(const int&, const void*, void*); + +void FoldStringConcatenate(const std::string&, const void*, void*); + +/* ************************************************************************** */ + +// BreadthMappableContainer member functions! + +template +void MapBreadth(uint& testnum, uint& testerr, lasd::BreadthMappableContainer& con, bool chk, typename lasd::BreadthMappableContainer::MapFunctor fun, const Parameter& inipar) { + bool tst = true; + testnum++; + Parameter par = {inipar}; + try { + std::cout << " " << testnum << " Executing map in pre order - "; + con.MapBreadth(fun, &par); + std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +// BreadthFoldableContainer member functions! + +template +void FoldBreadth(uint& testnum, uint& testerr, const lasd::BreadthFoldableContainer& con, bool chk, typename lasd::BreadthFoldableContainer::FoldFunctor fun, const Parameter& inipar, const Value& inival, const Value& finval) { + bool tst; + testnum++; + Parameter par = {inipar}; + Value val = inival; + try { + std::cout << " " << testnum << " Executing fold in post order - "; + con.FoldBreadth(fun, &par, &val); + std::cout << "obtained value is \"" << val << "\": "; + std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/exercise1/fulltest.cpp b/librerie/exercise2/zlasdtest/exercise1/fulltest.cpp new file mode 100755 index 0000000..27f84be --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise1/fulltest.cpp @@ -0,0 +1,3 @@ + +void testFullExercise1() { +} diff --git a/librerie/exercise2/zlasdtest/exercise1/simpletest.cpp b/librerie/exercise2/zlasdtest/exercise1/simpletest.cpp new file mode 100755 index 0000000..8fbc655 --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise1/simpletest.cpp @@ -0,0 +1,447 @@ + +#include + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +#include "../vector/vector.hpp" + +#include "../list/list.hpp" + +/* ************************************************************************** */ + +using namespace std; + +/* ************************************************************************** */ + +void stestVectorInt(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector Test:" << endl; + try { + { + lasd::Vector vec; + Empty(loctestnum, loctesterr, vec, true); + + GetFront(loctestnum, loctesterr, vec, false, 0); + GetBack(loctestnum, loctesterr, vec, false, 0); + SetAt(loctestnum, loctesterr, vec, false, 1, 0); + GetAt(loctestnum, loctesterr, vec, false, 2, 0); + + Exists(loctestnum, loctesterr, vec, false, 0); + + MapPreOrder(loctestnum, loctesterr, vec, true, &MapPrint, 0); + MapPostOrder(loctestnum, loctesterr, vec, true, &MapPrint, 0); + + FoldPreOrder(loctestnum, loctesterr, vec, true, &FoldAdd, 0, 0, 0); + FoldPostOrder(loctestnum, loctesterr, vec, true, &FoldAdd, 0, 0, 0); + } + { + lasd::Vector vec(3); + Empty(loctestnum, loctesterr, vec, false); + Size(loctestnum, loctesterr, vec, true, 3); + + SetAt(loctestnum, loctesterr, vec, true, 0, 4); + SetAt(loctestnum, loctesterr, vec, true, 1, 3); + SetAt(loctestnum, loctesterr, vec, true, 2, 1); + + GetFront(loctestnum, loctesterr, vec, true, 4); + GetBack(loctestnum, loctesterr, vec, true, 1); + + SetFront(loctestnum, loctesterr, vec, true, 5); + SetBack(loctestnum, loctesterr, vec, true, 4); + + Exists(loctestnum, loctesterr, vec, true, 4); + + MapPreOrder(loctestnum, loctesterr, vec, true, &MapPrint, 0); + MapPostOrder(loctestnum, loctesterr, vec, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, vec, true, &FoldAdd, 0, 0, 12); + FoldPostOrder(loctestnum, loctesterr, vec, true, &FoldMultiply, 0, 1, 60); + + vec.Resize(2); + FoldPostOrder(loctestnum, loctesterr, vec, true, &FoldMultiply, 0, 1, 15); + } + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVectorDouble(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector Test:" << endl; + try { + lasd::Vector vec(3); + Empty(loctestnum, loctesterr, vec, false); + Size(loctestnum, loctesterr, vec, true, 3); + + SetAt(loctestnum, loctesterr, vec, true, 0, 5.5); + SetAt(loctestnum, loctesterr, vec, true, 1, 3.3); + SetAt(loctestnum, loctesterr, vec, true, 2, 1.1); + + GetFront(loctestnum, loctesterr, vec, true, 5.5); + GetBack(loctestnum, loctesterr, vec, true, 1.1); + + Exists(loctestnum, loctesterr, vec, true, 3.3); + + FoldPreOrder(loctestnum, loctesterr, vec, true, &FoldAdd, 0.0, 0.0, 9.9); + FoldPostOrder(loctestnum, loctesterr, vec, true, &FoldMultiply, 0.0, 1.0, 19.965); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVectorString(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector Test:" << endl; + try { + lasd::Vector vec(2); + Empty(loctestnum, loctesterr, vec, false); + Size(loctestnum, loctesterr, vec, true, 2); + + SetAt(loctestnum, loctesterr, vec, true, 0, string("A")); + SetAt(loctestnum, loctesterr, vec, true, 1, string("B")); + + GetFront(loctestnum, loctesterr, vec, true, string("A")); + GetBack(loctestnum, loctesterr, vec, true, string("B")); + + Exists(loctestnum, loctesterr, vec, true, string("A")); + + MapPreOrder(loctestnum, loctesterr, vec, true, &MapStringAppend, string(" ")); + MapPreOrder(loctestnum, loctesterr, vec, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, vec, true, &FoldStringConcatenate, string(""), string("X"), string("XA B ")); + FoldPostOrder(loctestnum, loctesterr, vec, true, &FoldStringConcatenate, string(""), string("X"), string("XB A ")); + + Exists(loctestnum, loctesterr, vec, false, string("A")); + + lasd::Vector copvec(vec); + EqualVector(loctestnum, loctesterr, vec, copvec, true); + MapPreOrder(loctestnum, loctesterr, vec, true, &MapStringAppend, string("!")); + NonEqualVector(loctestnum, loctesterr, vec, copvec, true); + + copvec = std::move(vec); + FoldPreOrder(loctestnum, loctesterr, copvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A !B !")); + + lasd::Vector movvec(std::move(vec)); + FoldPreOrder(loctestnum, loctesterr, movvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A B ")); + SetAt(loctestnum, loctesterr, vec, false, 1, string("")); + vec.Resize(1); + SetAt(loctestnum, loctesterr, vec, true, 0, string("X")); + + movvec.Clear(); + Empty(loctestnum, loctesterr, movvec, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVector(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + stestVectorInt(loctestnum, loctesterr); + stestVectorDouble(loctestnum, loctesterr); + stestVectorString(loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; + cout << endl << "Exercise 1 - Vector (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} + +/* ************************************************************************** */ + +void stestListInt(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of List Test:" << endl; + try { + lasd::List lst; + Empty(loctestnum, loctesterr, lst, true); + Size(loctestnum, loctesterr, lst, true, 0); + + GetFront(loctestnum, loctesterr, lst, false, 0); + GetBack(loctestnum, loctesterr, lst, false, 0); + + Exists(loctestnum, loctesterr, lst, false, 0); + + MapPreOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + MapPostOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, lst, true, &FoldAdd, 0, 0, 0); + FoldPostOrder(loctestnum, loctesterr, lst, true, &FoldAdd, 0, 0, 0); + + RemoveFromFront(loctestnum, loctesterr, lst, false); + FrontNRemove(loctestnum, loctesterr, lst, false, 0); + + InsertAtBack(loctestnum, loctesterr, lst, true, 4); + InsertAtFront(loctestnum, loctesterr, lst, true, 5); + InsertAtFront(loctestnum, loctesterr, lst, true, 9); + InsertAtBack(loctestnum, loctesterr, lst, true, 2); + InsertAtFront(loctestnum, loctesterr, lst, true, 1); + + GetFront(loctestnum, loctesterr, lst, true, 1); + GetBack(loctestnum, loctesterr, lst, true, 2); + SetFront(loctestnum, loctesterr, lst, true, 2); + SetBack(loctestnum, loctesterr, lst, true, 6); + + GetAt(loctestnum, loctesterr, lst, true, 3, 4); + SetAt(loctestnum, loctesterr, lst, true, 3, 3); + + Exists(loctestnum, loctesterr, lst, false, 4); + + MapPreOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + MapPostOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, lst, true, &FoldAdd, 0, 0, 25); + FoldPostOrder(loctestnum, loctesterr, lst, true, &FoldMultiply, 0, 1, 1620); + + RemoveFromFront(loctestnum, loctesterr, lst, true); + FrontNRemove(loctestnum, loctesterr, lst, true, 9); + FoldPostOrder(loctestnum, loctesterr, lst, true, &FoldMultiply, 0, 1, 90); + + lasd::List coplst(lst); + EqualList(loctestnum, loctesterr, lst, coplst, true); + MapPreOrder(loctestnum, loctesterr, lst, true, &MapIncrement, 0); + NonEqualList(loctestnum, loctesterr, lst, coplst, true); + + InsertAtFront(loctestnum, loctesterr, lst, true, 0); + InsertAtBack(loctestnum, loctesterr, lst, true, 0); + NonEqualList(loctestnum, loctesterr, lst, coplst, true); + coplst = lst; + EqualList(loctestnum, loctesterr, lst, coplst, true); + + RemoveFromFront(loctestnum, loctesterr, coplst, true); + FrontNRemove(loctestnum, loctesterr, coplst, true, 6); + coplst = std::move(lst); + FoldPreOrder(loctestnum, loctesterr, lst, true, &FoldAdd, 0, 0, 11); + FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldAdd, 0, 0, 17); + + lasd::List movlst(std::move(lst)); + MapPreOrder(loctestnum, loctesterr, movlst, true, &MapIncrement, 0); + FoldPreOrder(loctestnum, loctesterr, movlst, true, &FoldAdd, 0, 0, 14); + + movlst.Clear(); + Empty(loctestnum, loctesterr, movlst, true); + Size(loctestnum, loctesterr, movlst, true, 0); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestListDouble(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of List Test:" << endl; + try { + lasd::List lst; + Empty(loctestnum, loctesterr, lst, true); + Size(loctestnum, loctesterr, lst, true, 0); + + InsertAtBack(loctestnum, loctesterr, lst, true, -2.5); + InsertAtBack(loctestnum, loctesterr, lst, true, 2.5); + + lst.Clear(); + + InsertAtBack(loctestnum, loctesterr, lst, true, 0.5); + InsertAtFront(loctestnum, loctesterr, lst, true, 3.3); + InsertAtFront(loctestnum, loctesterr, lst, true, 5.5); + InsertAtBack(loctestnum, loctesterr, lst, true, 1.1); + + GetFront(loctestnum, loctesterr, lst, true, 5.5); + GetBack(loctestnum, loctesterr, lst, true, 1.1); + + Exists(loctestnum, loctesterr, lst, false, 0.0); + + MapPreOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + MapPostOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, lst, true, &FoldAdd, 0.0, 0.0, 10.4); + FoldPostOrder(loctestnum, loctesterr, lst, true, &FoldMultiply, 0.0, 1.0, 9.9825); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestListString(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of List Test:" << endl; + try { + lasd::List lst; + Empty(loctestnum, loctesterr, lst, true); + Size(loctestnum, loctesterr, lst, true, 0); + + InsertAtFront(loctestnum, loctesterr, lst, true, string("A")); + InsertAtBack(loctestnum, loctesterr, lst, true, string("B")); + + GetFront(loctestnum, loctesterr, lst, true, string("A")); + GetBack(loctestnum, loctesterr, lst, true, string("B")); + + Exists(loctestnum, loctesterr, lst, true, string("B")); + + MapPreOrder(loctestnum, loctesterr, lst, true, &MapStringAppend, string(" ")); + MapPreOrder(loctestnum, loctesterr, lst, true, &MapPrint, 0); + FoldPreOrder(loctestnum, loctesterr, lst, true, &FoldStringConcatenate, string(""), string("X"), string("XA B ")); + FoldPostOrder(loctestnum, loctesterr, lst, true, &FoldStringConcatenate, string(""), string("X"), string("XB A ")); + + Exists(loctestnum, loctesterr, lst, false, string("B")); + + lasd::List coplst(lst); + EqualList(loctestnum, loctesterr, lst, coplst, true); + RemoveFromFront(loctestnum, loctesterr, coplst, true); + NonEqualList(loctestnum, loctesterr, lst, coplst, true); + + lst = coplst; + EqualList(loctestnum, loctesterr, lst, coplst, true); + InsertAtBack(loctestnum, loctesterr, lst, true, string("A")); + InsertAtFront(loctestnum, loctesterr, lst, true, string("C")); + NonEqualList(loctestnum, loctesterr, lst, coplst, true); + + coplst = std::move(lst); + FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldStringConcatenate, string(""), string("?"), string("?CB A")); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestList(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + stestListInt(loctestnum, loctesterr); + stestListDouble(loctestnum, loctesterr); + stestListString(loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; + cout << endl << "Exercise 1 - List (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} + +/* ************************************************************************** */ + +void stestVectorListInt(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector/List Test:" << endl; + try { + lasd::Vector vec(3); + SetAt(loctestnum, loctesterr, vec, true, 0, -1); + SetAt(loctestnum, loctesterr, vec, true, 1, 0); + SetAt(loctestnum, loctesterr, vec, true, 2, 1); + + lasd::List lst; + InsertAtFront(loctestnum, loctesterr, lst, true, 1); + InsertAtFront(loctestnum, loctesterr, lst, true, 0); + InsertAtFront(loctestnum, loctesterr, lst, true, -1); + + lasd::Vector copvec(lst); + EqualVector(loctestnum, loctesterr, vec, copvec, true); + lasd::Vector copvecx(vec); + EqualVector(loctestnum, loctesterr, copvecx, copvec, true); + + lasd::List coplst(vec); + EqualList(loctestnum, loctesterr, lst, coplst, true); + lasd::List coplstx(lst); + EqualList(loctestnum, loctesterr, coplstx, coplst, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector/List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVectorListDouble(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector/List Test:" << endl; + try { + lasd::Vector vec(3); + SetAt(loctestnum, loctesterr, vec, true, 0, -0.5); + SetAt(loctestnum, loctesterr, vec, true, 1, 0.0); + SetAt(loctestnum, loctesterr, vec, true, 2, 0.5); + + lasd::List lst; + InsertAtBack(loctestnum, loctesterr, lst, true, -0.5); + InsertAtBack(loctestnum, loctesterr, lst, true, 0.0); + InsertAtBack(loctestnum, loctesterr, lst, true, 0.5); + + lasd::Vector copvec(lst); + EqualVector(loctestnum, loctesterr, vec, copvec, true); + lasd::Vector copvecx(vec); + EqualVector(loctestnum, loctesterr, copvecx, copvec, true); + + lasd::List coplst(vec); + EqualList(loctestnum, loctesterr, lst, coplst, true); + lasd::List coplstx(lst); + EqualList(loctestnum, loctesterr, coplstx, coplst, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector/List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVectorListString(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + cout << endl << "Begin of Vector/List Test:" << endl; + try { + lasd::Vector vec(3); + SetAt(loctestnum, loctesterr, vec, true, 0, string("A")); + SetAt(loctestnum, loctesterr, vec, true, 1, string("B")); + SetAt(loctestnum, loctesterr, vec, true, 2, string("C")); + + lasd::List lst; + InsertAtFront(loctestnum, loctesterr, lst, true, string("B")); + InsertAtBack(loctestnum, loctesterr, lst, true, string("C")); + InsertAtFront(loctestnum, loctesterr, lst, true, string("A")); + + lasd::Vector copvec(lst); + EqualVector(loctestnum, loctesterr, vec, copvec, true); + lasd::Vector copvecx(vec); + EqualVector(loctestnum, loctesterr, copvecx, copvec, true); + + lasd::List coplst(vec); + EqualList(loctestnum, loctesterr, lst, coplst, true); + lasd::List coplstx(lst); + EqualList(loctestnum, loctesterr, coplstx, coplst, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + cout << "End of Vector/List Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; + testnum += loctestnum; + testerr += loctesterr; +} + +void stestVectorList(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + stestVectorListInt(loctestnum, loctesterr); + stestVectorListDouble(loctestnum, loctesterr); + stestVectorListString(loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; + cout << endl << "Exercise 1 - Vector/List (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} + +/* ************************************************************************** */ + +void testSimpleExercise1() { + uint testnum = 0, testerr = 0; + stestVector(testnum, testerr); + stestList(testnum, testerr); + stestVectorList(testnum, testerr); + cout << endl << "Exercise 1 (Simple Test) (Errors/Tests: " << testerr << "/" << testnum << ")" << endl; +} diff --git a/librerie/exercise2/zlasdtest/exercise1/test.hpp b/librerie/exercise2/zlasdtest/exercise1/test.hpp new file mode 100755 index 0000000..c151dcf --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise1/test.hpp @@ -0,0 +1,13 @@ + +#ifndef EX1TEST_HPP +#define EX1TEST_HPP + +/* ************************************************************************** */ + +void testSimpleExercise1(); + +void testFullExercise1(); + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/exercise2/fulltest.cpp b/librerie/exercise2/zlasdtest/exercise2/fulltest.cpp new file mode 100755 index 0000000..5d00543 --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise2/fulltest.cpp @@ -0,0 +1,3 @@ + +void testFullExercise2() { +} diff --git a/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp b/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp new file mode 100755 index 0000000..cbf8075 --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp @@ -0,0 +1,359 @@ + +#include + +/* ************************************************************************** */ + +#include "../container/container.hpp" + +#include "../stack/stack.hpp" +#include "../../stack/vec/stackvec.hpp" +#include "../../stack/lst/stacklst.hpp" + +#include "../queue/queue.hpp" +#include "../../queue/vec/queuevec.hpp" +#include "../../queue/lst/queuelst.hpp" + +/* ************************************************************************** */ + +using namespace std; + +/* ************************************************************************** */ + +template +void stestStackInt(Stk& stk, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + Empty(loctestnum, loctesterr, stk, true); + Size(loctestnum, loctesterr, stk, true, 0); + + Top(loctestnum, loctesterr, stk, false, 0); + TopNPop(loctestnum, loctesterr, stk, false, 0); + + PushC(loctestnum, loctesterr, stk, 4); + PushC(loctestnum, loctesterr, stk, 0); + PushC(loctestnum, loctesterr, stk, 3); + PushC(loctestnum, loctesterr, stk, 1); + PushC(loctestnum, loctesterr, stk, 2); + + Empty(loctestnum, loctesterr, stk, false); + Size(loctestnum, loctesterr, stk, true, 5); + + TopNPop(loctestnum, loctesterr, stk, true, 2); + Top(loctestnum, loctesterr, stk, true, 1); + + Stk copstk(stk); + EqualStack(loctestnum, loctesterr, stk, copstk, true); + PushC(loctestnum, loctesterr, stk, 5); + NonEqualStack(loctestnum, loctesterr, stk, copstk, true); + + copstk = stk; + EqualStack(loctestnum, loctesterr, stk, copstk, true); + PushC(loctestnum, loctesterr, copstk, 6); + NonEqualStack(loctestnum, loctesterr, stk, copstk, true); + + Top(loctestnum, loctesterr, copstk, true, 6); + copstk = std::move(stk); + TopNPop(loctestnum, loctesterr, copstk, true, 5); + Pop(loctestnum, loctesterr, copstk, true); + Top(loctestnum, loctesterr, copstk, true, 3); + + Stk movstk(std::move(stk)); + Top(loctestnum, loctesterr, stk, false, 0); + + movstk.Clear(); + Pop(loctestnum, loctesterr, movstk, false); + Empty(loctestnum, loctesterr, movstk, true); + Size(loctestnum, loctesterr, movstk, true, 0); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Stack Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestStackInt(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::StackVec stkvec; + cout << endl << "Begin of StackVec Test:" << endl; + stestStackInt(stkvec, loctestnum, loctesterr); + lasd::StackLst stklst; + cout << endl << "Begin of StackLst Test:" << endl; + stestStackInt(stklst, loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; +} + +template +void stestStackFloat(Stk& stk, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + PushC(loctestnum, loctesterr, stk, 5.9); + PushC(loctestnum, loctesterr, stk, 4.4); + PushC(loctestnum, loctesterr, stk, 9.5); + + Empty(loctestnum, loctesterr, stk, false); + Size(loctestnum, loctesterr, stk, true, 3); + + TopNPop(loctestnum, loctesterr, stk, true, 9.5); + Top(loctestnum, loctesterr, stk, true, 4.4); + Pop(loctestnum, loctesterr, stk, true); + TopNPop(loctestnum, loctesterr, stk, true, 5.9); + Pop(loctestnum, loctesterr, stk, false); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Stack Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestStackFloat(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::StackVec stkvec; + cout << endl << "Begin of StackVec Test:" << endl; + stestStackFloat(stkvec, loctestnum, loctesterr); + lasd::StackLst stklst; + cout << endl << "Begin of StackLst Test:" << endl; + stestStackFloat(stklst, loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; +} + +template +void stestStackString(Stk& stk, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + PushM(loctestnum, loctesterr, stk, string("A")); + PushM(loctestnum, loctesterr, stk, string("B")); + + Empty(loctestnum, loctesterr, stk, false); + Size(loctestnum, loctesterr, stk, true, 2); + + TopNPop(loctestnum, loctesterr, stk, true, string("B")); + Top(loctestnum, loctesterr, stk, true, string("A")); + Pop(loctestnum, loctesterr, stk, true); + Pop(loctestnum, loctesterr, stk, false); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Stack Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestStackString(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::StackVec stkvec; + cout << endl << "Begin of StackVec Test:" << endl; + stestStackString(stkvec, loctestnum, loctesterr); + lasd::StackLst stklst; + cout << endl << "Begin of StackLst Test:" << endl; + stestStackString(stklst, loctestnum, loctesterr); + cout << endl; + try { + lasd::Vector vec(2); + SetAt(loctestnum, loctesterr, vec, true, 0, string("A")); + SetAt(loctestnum, loctesterr, vec, true, 1, string("B")); + + PushM(loctestnum, loctesterr, stkvec, string("A")); + PushM(loctestnum, loctesterr, stkvec, string("B")); + lasd::StackVec newstkvec(vec); + EqualStack(loctestnum, loctesterr, stkvec, newstkvec, true); + + PushM(loctestnum, loctesterr, stklst, string("B")); + PushM(loctestnum, loctesterr, stklst, string("A")); + lasd::StackLst newstklst(vec); + EqualStack(loctestnum, loctesterr, stklst, newstklst, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; +} + +void stestStack(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + stestStackInt(loctestnum, loctesterr); + stestStackFloat(loctestnum, loctesterr); + stestStackString(loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; + cout << endl << "Exercise 2 - Stack (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} + +/* ************************************************************************** */ + +template +void stestQueueInt(Que& que, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + Empty(loctestnum, loctesterr, que, true); + Size(loctestnum, loctesterr, que, true, 0); + + Head(loctestnum, loctesterr, que, false, 0); + HeadNDequeue(loctestnum, loctesterr, que, false, 0); + + EnqueueC(loctestnum, loctesterr, que, 4); + EnqueueC(loctestnum, loctesterr, que, 0); + EnqueueC(loctestnum, loctesterr, que, 3); + EnqueueC(loctestnum, loctesterr, que, 1); + EnqueueC(loctestnum, loctesterr, que, 2); + + Empty(loctestnum, loctesterr, que, false); + Size(loctestnum, loctesterr, que, true, 5); + + HeadNDequeue(loctestnum, loctesterr, que, true, 4); + Head(loctestnum, loctesterr, que, true, 0); + + Que copque(que); + EqualQueue(loctestnum, loctesterr, que, copque, true); + EnqueueC(loctestnum, loctesterr, que, 5); + NonEqualQueue(loctestnum, loctesterr, que, copque, true); + + copque = que; + EqualQueue(loctestnum, loctesterr, que, copque, true); + EnqueueC(loctestnum, loctesterr, copque, 6); + NonEqualQueue(loctestnum, loctesterr, que, copque, true); + + Head(loctestnum, loctesterr, copque, true, 0); + copque = std::move(que); + HeadNDequeue(loctestnum, loctesterr, copque, true, 0); + Dequeue(loctestnum, loctesterr, copque, true); + Head(loctestnum, loctesterr, copque, true, 1); + + Que movque(std::move(que)); + Head(loctestnum, loctesterr, que, false, 0); + + movque.Clear(); + Dequeue(loctestnum, loctesterr, movque, false); + Empty(loctestnum, loctesterr, movque, true); + Size(loctestnum, loctesterr, movque, true, 0); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Queue Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestQueueInt(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::QueueVec quevec; + cout << endl << "Begin of QueueVec Test:" << endl; + stestQueueInt(quevec, loctestnum, loctesterr); + lasd::QueueLst quelst; + cout << endl << "Begin of QueueLst Test:" << endl; + stestQueueInt(quelst, loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; +} + +template +void stestQueueFloat(Que& que, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + EnqueueC(loctestnum, loctesterr, que, 5.9); + EnqueueC(loctestnum, loctesterr, que, 4.4); + EnqueueC(loctestnum, loctesterr, que, 9.5); + + Empty(loctestnum, loctesterr, que, false); + Size(loctestnum, loctesterr, que, true, 3); + + HeadNDequeue(loctestnum, loctesterr, que, true, 5.9); + Head(loctestnum, loctesterr, que, true, 4.4); + Dequeue(loctestnum, loctesterr, que, true); + HeadNDequeue(loctestnum, loctesterr, que, true, 9.5); + Dequeue(loctestnum, loctesterr, que, false); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Queue Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestQueueFloat(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::QueueVec quevec; + cout << endl << "Begin of QueueVec Test:" << endl; + stestQueueFloat(quevec, loctestnum, loctesterr); + lasd::QueueLst quelst; + cout << endl << "Begin of QueueLst Test:" << endl; + stestQueueFloat(quelst, loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; +} + +template +void stestQueueString(Que& que, uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + try { + EnqueueM(loctestnum, loctesterr, que, string("A")); + EnqueueM(loctestnum, loctesterr, que, string("B")); + + Empty(loctestnum, loctesterr, que, false); + Size(loctestnum, loctesterr, que, true, 2); + + HeadNDequeue(loctestnum, loctesterr, que, true, string("A")); + Head(loctestnum, loctesterr, que, true, string("B")); + Dequeue(loctestnum, loctesterr, que, true); + Dequeue(loctestnum, loctesterr, que, false); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; + cout << "End of Queue Test! (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} +void stestQueueString(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + lasd::QueueVec quevec; + cout << endl << "Begin of QueueVec Test:" << endl; + stestQueueString(quevec, loctestnum, loctesterr); + lasd::QueueLst quelst; + cout << endl << "Begin of QueueLst Test:" << endl; + stestQueueString(quelst, loctestnum, loctesterr); + cout << endl; + try { + lasd::Vector vec(2); + SetAt(loctestnum, loctesterr, vec, true, 0, string("A")); + SetAt(loctestnum, loctesterr, vec, true, 1, string("B")); + + EnqueueM(loctestnum, loctesterr, quevec, string("A")); + EnqueueM(loctestnum, loctesterr, quevec, string("B")); + lasd::QueueVec newquevec(vec); + EqualStack(loctestnum, loctesterr, quevec, newquevec, true); + + EnqueueM(loctestnum, loctesterr, quelst, string("A")); + EnqueueM(loctestnum, loctesterr, quelst, string("B")); + lasd::QueueLst newquelst(vec); + EqualStack(loctestnum, loctesterr, quelst, newquelst, true); + } catch(...) { + loctestnum++; loctesterr++; + cout << endl << "Unmanaged error! " << endl; + } + testnum += loctestnum; + testerr += loctesterr; +} + +void stestQueue(uint& testnum, uint& testerr) { + uint loctestnum = 0, loctesterr = 0; + stestQueueInt(loctestnum, loctesterr); + stestQueueFloat(loctestnum, loctesterr); + stestQueueString(loctestnum, loctesterr); + testnum += loctestnum; + testerr += loctesterr; + cout << endl << "Exercise 2 - Queue (Errors/Tests: " << loctesterr << "/" << loctestnum << ")" << endl; +} + +/* ************************************************************************** */ + +void testSimpleExercise2() { + uint testnum = 0, testerr = 0; + stestStack(testnum, testerr); + stestQueue(testnum, testerr); + cout << endl << "Exercise 2 (Simple Test) (Errors/Tests: " << testerr << "/" << testnum << ")" << endl; +} diff --git a/librerie/exercise2/zlasdtest/exercise2/test.hpp b/librerie/exercise2/zlasdtest/exercise2/test.hpp new file mode 100755 index 0000000..eb1a7f1 --- /dev/null +++ b/librerie/exercise2/zlasdtest/exercise2/test.hpp @@ -0,0 +1,13 @@ + +#ifndef EX2TEST_HPP +#define EX2TEST_HPP + +/* ************************************************************************** */ + +void testSimpleExercise2(); + +void testFullExercise2(); + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/list/list.hpp b/librerie/exercise2/zlasdtest/list/list.hpp new file mode 100755 index 0000000..0a8d7a0 --- /dev/null +++ b/librerie/exercise2/zlasdtest/list/list.hpp @@ -0,0 +1,98 @@ + +#ifndef LISTTEST_HPP +#define LISTTEST_HPP + +#include "../../list/list.hpp" + +/* ************************************************************************** */ + +template +void InsertAtFront(uint& testnum, uint& testerr, lasd::List& lst, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Insert at the front of the list the value \"" << val << "\": "; + lst.InsertAtFront(val); + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void RemoveFromFront(uint& testnum, uint& testerr, lasd::List& lst, bool chk) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Remove from the list of \"" << lst.Front() << "\": "; + lst.RemoveFromFront(); + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void FrontNRemove(uint& testnum, uint& testerr, lasd::List& lst, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " FrontNRemove from the list of \"" << lst.Front() << "\": "; + std::cout << ((tst = ((lst.FrontNRemove() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void InsertAtBack(uint& testnum, uint& testerr, lasd::List& lst, bool chk, const Data& val) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " Insert at the back of the list the value \"" << val << "\": "; + lst.InsertAtBack(val); + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void EqualList(uint& testnum, uint& testerr, const lasd::List& lst1, const lasd::List& lst2, bool chk) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The two lists are " << ((tst = (lst1 == lst2)) ? "" : "not ") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void NonEqualList(uint& testnum, uint& testerr, const lasd::List& lst1, const lasd::List& lst2, bool chk) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The two lists are " << ((tst = (lst1 != lst2)) ? "not " : "") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/queue/queue.hpp b/librerie/exercise2/zlasdtest/queue/queue.hpp new file mode 100755 index 0000000..438ed29 --- /dev/null +++ b/librerie/exercise2/zlasdtest/queue/queue.hpp @@ -0,0 +1,116 @@ + +#ifndef QUEUETEST_HPP +#define QUEUETEST_HPP + +#include "../../queue/queue.hpp" + +/* ************************************************************************** */ + +template +void EnqueueC(uint& testnum, uint& testerr, lasd::Queue& que, const Data& val) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Enqueue on the queue of the value \"" << val << "\": "; + que.Enqueue(val); + std::cout << "Correct!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; + tst = false; + } + testerr += (1 - (uint) tst); +} + +template +void EnqueueM(uint& testnum, uint& testerr, lasd::Queue& que, Data val) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Enqueue on the queue of the value \"" << val << "\": "; + que.Enqueue(std::move(val)); + std::cout << "Correct!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; + tst = false; + } + testerr += (1 - (uint) tst); +} + +template +void Head(uint& testnum, uint& testerr, lasd::Queue& que, bool chk, const Data& val) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " Head of the queue with value \"" << que.Head() << "\": "; + std::cout << ((tst = ((que.Head() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void Dequeue(uint& testnum, uint& testerr, lasd::Queue& que, bool chk) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Dequeue from the queue: "; + que.Dequeue(); + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void HeadNDequeue(uint& testnum, uint& testerr, lasd::Queue& que, bool chk, const Data& val) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " HeadNDequeue from the queue with value \"" << que.Head() << "\": "; + std::cout << ((tst = ((que.HeadNDequeue() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void EqualQueue(uint& testnum, uint& testerr, const Que& que1, const Que& que2, bool chk) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " The two queues are " << ((tst = (que1 == que2)) ? "" : "not ") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void NonEqualQueue(uint& testnum, uint& testerr, const Que& que1, const Que& que2, bool chk) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " The two queues are " << ((tst = (que1 != que2)) ? "not " : "") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/stack/stack.hpp b/librerie/exercise2/zlasdtest/stack/stack.hpp new file mode 100755 index 0000000..018cdd7 --- /dev/null +++ b/librerie/exercise2/zlasdtest/stack/stack.hpp @@ -0,0 +1,116 @@ + +#ifndef STACKTEST_HPP +#define STACKTEST_HPP + +#include "../../stack/stack.hpp" + +/* ************************************************************************** */ + +template +void PushC(uint& testnum, uint& testerr, lasd::Stack& stk, const Data& val) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Push on the stack of the value \"" << val << "\": "; + stk.Push(val); + std::cout << "Correct!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; + tst = false; + } + testerr += (1 - (uint) tst); +} + +template +void PushM(uint& testnum, uint& testerr, lasd::Stack& stk, Data val) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Push on the stack of the value \"" << val << "\": "; + stk.Push(std::move(val)); + std::cout << "Correct!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; + tst = false; + } + testerr += (1 - (uint) tst); +} + +template +void Top(uint& testnum, uint& testerr, lasd::Stack& stk, bool chk, const Data& val) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " Top of the stack with value \"" << stk.Top() << "\": "; + std::cout << ((tst = ((stk.Top() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void Pop(uint& testnum, uint& testerr, lasd::Stack& stk, bool chk) { + testnum++; + bool tst = true; + try { + std::cout << " " << testnum << " Pop from the stack: "; + stk.Pop(); + std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void TopNPop(uint& testnum, uint& testerr, lasd::Stack& stk, bool chk, const Data& val) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " TopNPop from the stack with value \"" << stk.Top() << "\": "; + std::cout << ((tst = ((stk.TopNPop() == val) == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::length_error exc) { + std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + tst = false; + std::cout << std::endl << "Wrong exception: " << exc.what() << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void EqualStack(uint& testnum, uint& testerr, const Stk& stk1, const Stk& stk2, bool chk) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " The two stacks are " << ((tst = (stk1 == stk2)) ? "" : "not ") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void NonEqualStack(uint& testnum, uint& testerr, const Stk& stk1, const Stk& stk2, bool chk) { + testnum++; + bool tst; + try { + std::cout << " " << testnum << " The two stacks are " << ((tst = (stk1 != stk2)) ? "not " : "") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/test.cpp b/librerie/exercise2/zlasdtest/test.cpp new file mode 100755 index 0000000..79c876e --- /dev/null +++ b/librerie/exercise2/zlasdtest/test.cpp @@ -0,0 +1,21 @@ + +#include "./exercise1/test.hpp" + +#include "./exercise2/test.hpp" + +/* ************************************************************************** */ + +#include + +using namespace std; + +/* ************************************************************************** */ + +void lasdtest() { + cout << endl << "~*~#~*~ Welcome to the LASD Test Suite ~*~#~*~ " << endl; + testSimpleExercise1(); + testFullExercise1(); + testSimpleExercise2(); + testFullExercise2(); + cout << endl << "Goodbye!" << endl; +} diff --git a/librerie/exercise2/zlasdtest/test.hpp b/librerie/exercise2/zlasdtest/test.hpp new file mode 100755 index 0000000..a2fca61 --- /dev/null +++ b/librerie/exercise2/zlasdtest/test.hpp @@ -0,0 +1,11 @@ + +#ifndef LASDTEST_HPP +#define LASDTEST_HPP + +/* ************************************************************************** */ + +void lasdtest(); + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zlasdtest/vector/vector.hpp b/librerie/exercise2/zlasdtest/vector/vector.hpp new file mode 100755 index 0000000..bb0ccf6 --- /dev/null +++ b/librerie/exercise2/zlasdtest/vector/vector.hpp @@ -0,0 +1,37 @@ + +#ifndef VECTORTEST_HPP +#define VECTORTEST_HPP + +#include "../../vector/vector.hpp" + +/* ************************************************************************** */ + +template +void EqualVector(uint& testnum, uint& testerr, const lasd::Vector& vec1, const lasd::Vector& vec2, bool chk) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The two vectors are " << ((tst = (vec1 == vec2)) ? "" : "not ") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +template +void NonEqualVector(uint& testnum, uint& testerr, const lasd::Vector& vec1, const lasd::Vector& vec2, bool chk) { + bool tst; + testnum++; + try { + std::cout << " " << testnum << " The two vectors are " << ((tst = (vec1 != vec2)) ? "not " : "") << "equal: "; + std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl; + } catch(std::exception exc) { + std::cout << "\"" << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl; + } + testerr += (1 - (uint) tst); +} + +/* ************************************************************************** */ + +#endif diff --git a/librerie/exercise2/zmytest/test.cpp b/librerie/exercise2/zmytest/test.cpp new file mode 100755 index 0000000..07a921d --- /dev/null +++ b/librerie/exercise2/zmytest/test.cpp @@ -0,0 +1,2 @@ + +// ... diff --git a/librerie/exercise2/zmytest/test.hpp b/librerie/exercise2/zmytest/test.hpp new file mode 100755 index 0000000..99b9987 --- /dev/null +++ b/librerie/exercise2/zmytest/test.hpp @@ -0,0 +1,11 @@ + +#ifndef MYTEST_HPP +#define MYTEST_HPP + +/* ************************************************************************** */ + +// ... + +/* ************************************************************************** */ + +#endif