diff --git a/librerie/exercise2/main b/librerie/exercise2/main index ed1ea80..1434c93 100755 Binary files a/librerie/exercise2/main and b/librerie/exercise2/main differ diff --git a/librerie/exercise2/queue/vec/queuevec.cpp b/librerie/exercise2/queue/vec/queuevec.cpp index cac631c..0f7a83d 100755 --- a/librerie/exercise2/queue/vec/queuevec.cpp +++ b/librerie/exercise2/queue/vec/queuevec.cpp @@ -37,9 +37,7 @@ QueueVec::QueueVec(const QueueVec& toCopy){ template QueueVec::QueueVec(QueueVec&& toMove) noexcept{ - /* we initialize size=4 so the swapped vector won't be in an - inconsistent state (size=0 can never be acceptable) */ - size = 4; + Clear(); std::swap(Elements, toMove.Elements); std::swap(rear, toMove.rear); std::swap(front, toMove.front); @@ -61,8 +59,6 @@ QueueVec& QueueVec::operator=(const QueueVec& toCopy){ template QueueVec& QueueVec::operator=(QueueVec&& toMove) noexcept{ - /* here we do not need size=4 since the QueueVec with at least size=4 - exists already */ std::swap(Elements, toMove.Elements); std::swap(size, toMove.size); std::swap(rear, toMove.rear); @@ -144,6 +140,7 @@ bool QueueVec::Empty() const noexcept{ template ulong QueueVec::Size() const noexcept{ + if(size == 0) return 0; // this won't ever get executed, it's here just in case return ((rear + size) - front) % size; } diff --git a/librerie/exercise2/vector/vector.cpp b/librerie/exercise2/vector/vector.cpp index 2ebef36..7f02416 100644 --- a/librerie/exercise2/vector/vector.cpp +++ b/librerie/exercise2/vector/vector.cpp @@ -93,7 +93,6 @@ template } } - template void Vector::Clear(){ delete[] Elements; diff --git a/librerie/exercise2/zlasdtest/container/container.cpp b/librerie/exercise2/zlasdtest/container/container.cpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/container/container.hpp b/librerie/exercise2/zlasdtest/container/container.hpp old mode 100755 new mode 100644 index d1503cc..9d571a7 --- a/librerie/exercise2/zlasdtest/container/container.hpp +++ b/librerie/exercise2/zlasdtest/container/container.hpp @@ -39,7 +39,7 @@ void SetFront(uint& testnum, uint& testerr, const lasd::LinearContainer& c try { std::cout << " " << testnum << " Setting the front of the linear container to \"" << val << "\": "; con.Front() = val; - std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + 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) { @@ -72,7 +72,7 @@ void SetBack(uint& testnum, uint& testerr, const lasd::LinearContainer& co try { std::cout << " " << testnum << " Setting the back of the linear container to \"" << val << "\": "; con.Back() = val; - std::cout << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl; + 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) { @@ -82,23 +82,6 @@ void SetBack(uint& testnum, uint& testerr, const lasd::LinearContainer& co 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; @@ -115,6 +98,23 @@ void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer& con, bool 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 = ((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! @@ -172,6 +172,11 @@ void MapIncrement(Data& dat, void* _) { dat++; } +template +void MapDecrement(Data& dat, void* _) { + dat--; +} + template void MapIncrementNPrint(Data& dat, void* _) { std::cout << dat++ << "->" << dat << "; "; @@ -182,6 +187,11 @@ void MapDouble(Data& dat, void* _) { dat *= 2; } +template +void MapHalf(Data& dat, void* _) { + dat /= 2; +} + template void MapDoubleNPrint(Data& dat, void* _) { std::cout << dat << "->" << (dat *= 2) << "; "; @@ -266,7 +276,7 @@ void MapBreadth(uint& testnum, uint& testerr, lasd::BreadthMappableContainer movvec(std::move(vec)); + lasd::Vector movvec(move(vec)); FoldPreOrder(loctestnum, loctesterr, movvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A B ")); SetAt(loctestnum, loctesterr, vec, false, 1, string("")); vec.Resize(1); @@ -217,11 +217,11 @@ void stestListInt(uint& testnum, uint& testerr) { RemoveFromFront(loctestnum, loctesterr, coplst, true); FrontNRemove(loctestnum, loctesterr, coplst, true, 6); - coplst = std::move(lst); + coplst = 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)); + lasd::List movlst(move(lst)); MapPreOrder(loctestnum, loctesterr, movlst, true, &MapIncrement, 0); FoldPreOrder(loctestnum, loctesterr, movlst, true, &FoldAdd, 0, 0, 14); @@ -307,7 +307,7 @@ void stestListString(uint& testnum, uint& testerr) { InsertAtFront(loctestnum, loctesterr, lst, true, string("C")); NonEqualList(loctestnum, loctesterr, lst, coplst, true); - coplst = std::move(lst); + coplst = move(lst); FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldStringConcatenate, string(""), string("?"), string("?CB A")); } catch(...) { loctestnum++; loctesterr++; diff --git a/librerie/exercise2/zlasdtest/exercise1/test.hpp b/librerie/exercise2/zlasdtest/exercise1/test.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/exercise2/fulltest.cpp b/librerie/exercise2/zlasdtest/exercise2/fulltest.cpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp b/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp old mode 100755 new mode 100644 index cbf8075..beaa23f --- a/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp +++ b/librerie/exercise2/zlasdtest/exercise2/simpletest.cpp @@ -52,12 +52,12 @@ void stestStackInt(Stk& stk, uint& testnum, uint& testerr) { NonEqualStack(loctestnum, loctesterr, stk, copstk, true); Top(loctestnum, loctesterr, copstk, true, 6); - copstk = std::move(stk); + copstk = move(stk); TopNPop(loctestnum, loctesterr, copstk, true, 5); Pop(loctestnum, loctesterr, copstk, true); Top(loctestnum, loctesterr, copstk, true, 3); - Stk movstk(std::move(stk)); + Stk movstk(move(stk)); Top(loctestnum, loctesterr, stk, false, 0); movstk.Clear(); @@ -218,12 +218,12 @@ void stestQueueInt(Que& que, uint& testnum, uint& testerr) { NonEqualQueue(loctestnum, loctesterr, que, copque, true); Head(loctestnum, loctesterr, copque, true, 0); - copque = std::move(que); + copque = move(que); HeadNDequeue(loctestnum, loctesterr, copque, true, 0); Dequeue(loctestnum, loctesterr, copque, true); Head(loctestnum, loctesterr, copque, true, 1); - Que movque(std::move(que)); + Que movque(move(que)); Head(loctestnum, loctesterr, que, false, 0); movque.Clear(); @@ -325,12 +325,12 @@ void stestQueueString(uint& testnum, uint& testerr) { EnqueueM(loctestnum, loctesterr, quevec, string("A")); EnqueueM(loctestnum, loctesterr, quevec, string("B")); lasd::QueueVec newquevec(vec); - EqualStack(loctestnum, loctesterr, quevec, newquevec, true); + EqualQueue(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); + EqualQueue(loctestnum, loctesterr, quelst, newquelst, true); } catch(...) { loctestnum++; loctesterr++; cout << endl << "Unmanaged error! " << endl; diff --git a/librerie/exercise2/zlasdtest/exercise2/test.hpp b/librerie/exercise2/zlasdtest/exercise2/test.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/list/list.hpp b/librerie/exercise2/zlasdtest/list/list.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/queue/queue.hpp b/librerie/exercise2/zlasdtest/queue/queue.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/stack/stack.hpp b/librerie/exercise2/zlasdtest/stack/stack.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/test.cpp b/librerie/exercise2/zlasdtest/test.cpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/test.hpp b/librerie/exercise2/zlasdtest/test.hpp old mode 100755 new mode 100644 diff --git a/librerie/exercise2/zlasdtest/vector/vector.hpp b/librerie/exercise2/zlasdtest/vector/vector.hpp old mode 100755 new mode 100644