Library 2

bugfix and professor edited its tests
This commit is contained in:
Alessandro Ferro 2021-04-23 20:16:33 +02:00
parent 31570d2ad4
commit 67c0f1c0d5
17 changed files with 44 additions and 38 deletions

Binary file not shown.

View File

@ -37,9 +37,7 @@ QueueVec<Data>::QueueVec(const QueueVec& toCopy){
template <typename Data>
QueueVec<Data>::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<Data>& QueueVec<Data>::operator=(const QueueVec& toCopy){
template <typename Data>
QueueVec<Data>& QueueVec<Data>::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<Data>::Empty() const noexcept{
template <typename Data>
ulong QueueVec<Data>::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;
}

View File

@ -93,7 +93,6 @@ template <typename Data>
}
}
template <typename Data>
void Vector<Data>::Clear(){
delete[] Elements;

0
librerie/exercise2/zlasdtest/container/container.cpp Executable file → Normal file
View File

52
librerie/exercise2/zlasdtest/container/container.hpp Executable file → Normal file
View File

@ -39,7 +39,7 @@ void SetFront(uint& testnum, uint& testerr, const lasd::LinearContainer<Data>& 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<Data>& 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<Data>& co
testerr += (1 - (uint) tst);
}
template <typename Data>
void SetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& 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 <typename Data>
void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& con, bool chk, const ulong& ind, const Data& val) {
bool tst;
@ -115,6 +98,23 @@ void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& con, bool
testerr += (1 - (uint) tst);
}
template <typename Data>
void SetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& 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 <typename Data>
void MapDecrement(Data& dat, void* _) {
dat--;
}
template <typename Data>
void MapIncrementNPrint(Data& dat, void* _) {
std::cout << dat++ << "->" << dat << "; ";
@ -182,6 +187,11 @@ void MapDouble(Data& dat, void* _) {
dat *= 2;
}
template <typename Data>
void MapHalf(Data& dat, void* _) {
dat /= 2;
}
template <typename Data>
void MapDoubleNPrint(Data& dat, void* _) {
std::cout << dat << "->" << (dat *= 2) << "; ";
@ -266,7 +276,7 @@ void MapBreadth(uint& testnum, uint& testerr, lasd::BreadthMappableContainer<Dat
testnum++;
Parameter par = {inipar};
try {
std::cout << " " << testnum << " Executing map in pre order - ";
std::cout << " " << testnum << " Executing map in breadth - ";
con.MapBreadth(fun, &par);
std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl;
} catch(std::exception exc) {
@ -286,7 +296,7 @@ void FoldBreadth(uint& testnum, uint& testerr, const lasd::BreadthFoldableContai
Parameter par = {inipar};
Value val = inival;
try {
std::cout << " " << testnum << " Executing fold in post order - ";
std::cout << " " << testnum << " Executing fold in breadth - ";
con.FoldBreadth(fun, &par, &val);
std::cout << "obtained value is \"" << val << "\": ";
std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl;

0
librerie/exercise2/zlasdtest/exercise1/fulltest.cpp Executable file → Normal file
View File

10
librerie/exercise2/zlasdtest/exercise1/simpletest.cpp Executable file → Normal file
View File

@ -126,10 +126,10 @@ void stestVectorString(uint& testnum, uint& testerr) {
MapPreOrder(loctestnum, loctesterr, vec, true, &MapStringAppend, string("!"));
NonEqualVector(loctestnum, loctesterr, vec, copvec, true);
copvec = std::move(vec);
copvec = move(vec);
FoldPreOrder(loctestnum, loctesterr, copvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A !B !"));
lasd::Vector<string> movvec(std::move(vec));
lasd::Vector<string> 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<int>, 0, 0, 11);
FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldAdd<int>, 0, 0, 17);
lasd::List<int> movlst(std::move(lst));
lasd::List<int> movlst(move(lst));
MapPreOrder(loctestnum, loctesterr, movlst, true, &MapIncrement<int>, 0);
FoldPreOrder(loctestnum, loctesterr, movlst, true, &FoldAdd<int>, 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++;

0
librerie/exercise2/zlasdtest/exercise1/test.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/exercise2/fulltest.cpp Executable file → Normal file
View File

12
librerie/exercise2/zlasdtest/exercise2/simpletest.cpp Executable file → Normal file
View File

@ -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<string> 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<string> newquelst(vec);
EqualStack(loctestnum, loctesterr, quelst, newquelst, true);
EqualQueue(loctestnum, loctesterr, quelst, newquelst, true);
} catch(...) {
loctestnum++; loctesterr++;
cout << endl << "Unmanaged error! " << endl;

0
librerie/exercise2/zlasdtest/exercise2/test.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/list/list.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/queue/queue.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/stack/stack.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/test.cpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/test.hpp Executable file → Normal file
View File

0
librerie/exercise2/zlasdtest/vector/vector.hpp Executable file → Normal file
View File