mirror of https://github.com/xfarrow/lasd.git
parent
31570d2ad4
commit
67c0f1c0d5
Binary file not shown.
|
@ -37,9 +37,7 @@ QueueVec<Data>::QueueVec(const QueueVec& toCopy){
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
QueueVec<Data>::QueueVec(QueueVec&& toMove) noexcept{
|
QueueVec<Data>::QueueVec(QueueVec&& toMove) noexcept{
|
||||||
/* we initialize size=4 so the swapped vector won't be in an
|
Clear();
|
||||||
inconsistent state (size=0 can never be acceptable) */
|
|
||||||
size = 4;
|
|
||||||
std::swap(Elements, toMove.Elements);
|
std::swap(Elements, toMove.Elements);
|
||||||
std::swap(rear, toMove.rear);
|
std::swap(rear, toMove.rear);
|
||||||
std::swap(front, toMove.front);
|
std::swap(front, toMove.front);
|
||||||
|
@ -61,8 +59,6 @@ QueueVec<Data>& QueueVec<Data>::operator=(const QueueVec& toCopy){
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
QueueVec<Data>& QueueVec<Data>::operator=(QueueVec&& toMove) noexcept{
|
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(Elements, toMove.Elements);
|
||||||
std::swap(size, toMove.size);
|
std::swap(size, toMove.size);
|
||||||
std::swap(rear, toMove.rear);
|
std::swap(rear, toMove.rear);
|
||||||
|
@ -144,6 +140,7 @@ bool QueueVec<Data>::Empty() const noexcept{
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
ulong QueueVec<Data>::Size() const noexcept{
|
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;
|
return ((rear + size) - front) % size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,6 @@ template <typename Data>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void Vector<Data>::Clear(){
|
void Vector<Data>::Clear(){
|
||||||
delete[] Elements;
|
delete[] Elements;
|
||||||
|
|
|
@ -39,7 +39,7 @@ void SetFront(uint& testnum, uint& testerr, const lasd::LinearContainer<Data>& c
|
||||||
try {
|
try {
|
||||||
std::cout << " " << testnum << " Setting the front of the linear container to \"" << val << "\": ";
|
std::cout << " " << testnum << " Setting the front of the linear container to \"" << val << "\": ";
|
||||||
con.Front() = 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) {
|
} catch(std::length_error exc) {
|
||||||
std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl;
|
std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl;
|
||||||
} catch(std::exception exc) {
|
} catch(std::exception exc) {
|
||||||
|
@ -72,7 +72,7 @@ void SetBack(uint& testnum, uint& testerr, const lasd::LinearContainer<Data>& co
|
||||||
try {
|
try {
|
||||||
std::cout << " " << testnum << " Setting the back of the linear container to \"" << val << "\": ";
|
std::cout << " " << testnum << " Setting the back of the linear container to \"" << val << "\": ";
|
||||||
con.Back() = 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) {
|
} catch(std::length_error exc) {
|
||||||
std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl;
|
std::cout << exc.what() << "\": " << ((tst = !chk) ? "Correct" : "Error") << "!" << std::endl;
|
||||||
} catch(std::exception exc) {
|
} catch(std::exception exc) {
|
||||||
|
@ -82,23 +82,6 @@ void SetBack(uint& testnum, uint& testerr, const lasd::LinearContainer<Data>& co
|
||||||
testerr += (1 - (uint) tst);
|
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>
|
template <typename Data>
|
||||||
void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& con, bool chk, const ulong& ind, const Data& val) {
|
void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& con, bool chk, const ulong& ind, const Data& val) {
|
||||||
bool tst;
|
bool tst;
|
||||||
|
@ -115,6 +98,23 @@ void GetAt(uint& testnum, uint& testerr, lasd::LinearContainer<Data>& con, bool
|
||||||
testerr += (1 - (uint) tst);
|
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!
|
// TestableContainer member functions!
|
||||||
|
@ -172,6 +172,11 @@ void MapIncrement(Data& dat, void* _) {
|
||||||
dat++;
|
dat++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
void MapDecrement(Data& dat, void* _) {
|
||||||
|
dat--;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void MapIncrementNPrint(Data& dat, void* _) {
|
void MapIncrementNPrint(Data& dat, void* _) {
|
||||||
std::cout << dat++ << "->" << dat << "; ";
|
std::cout << dat++ << "->" << dat << "; ";
|
||||||
|
@ -182,6 +187,11 @@ void MapDouble(Data& dat, void* _) {
|
||||||
dat *= 2;
|
dat *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
void MapHalf(Data& dat, void* _) {
|
||||||
|
dat /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void MapDoubleNPrint(Data& dat, void* _) {
|
void MapDoubleNPrint(Data& dat, void* _) {
|
||||||
std::cout << dat << "->" << (dat *= 2) << "; ";
|
std::cout << dat << "->" << (dat *= 2) << "; ";
|
||||||
|
@ -266,7 +276,7 @@ void MapBreadth(uint& testnum, uint& testerr, lasd::BreadthMappableContainer<Dat
|
||||||
testnum++;
|
testnum++;
|
||||||
Parameter par = {inipar};
|
Parameter par = {inipar};
|
||||||
try {
|
try {
|
||||||
std::cout << " " << testnum << " Executing map in pre order - ";
|
std::cout << " " << testnum << " Executing map in breadth - ";
|
||||||
con.MapBreadth(fun, &par);
|
con.MapBreadth(fun, &par);
|
||||||
std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl;
|
std::cout << ": " << ((tst = chk) ? "Correct" : "Error") << "!" << std::endl;
|
||||||
} catch(std::exception exc) {
|
} catch(std::exception exc) {
|
||||||
|
@ -286,7 +296,7 @@ void FoldBreadth(uint& testnum, uint& testerr, const lasd::BreadthFoldableContai
|
||||||
Parameter par = {inipar};
|
Parameter par = {inipar};
|
||||||
Value val = inival;
|
Value val = inival;
|
||||||
try {
|
try {
|
||||||
std::cout << " " << testnum << " Executing fold in post order - ";
|
std::cout << " " << testnum << " Executing fold in breadth - ";
|
||||||
con.FoldBreadth(fun, &par, &val);
|
con.FoldBreadth(fun, &par, &val);
|
||||||
std::cout << "obtained value is \"" << val << "\": ";
|
std::cout << "obtained value is \"" << val << "\": ";
|
||||||
std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl;
|
std::cout << ((tst = ((val == finval) == chk)) ? "Correct" : "Error") << "!" << std::endl;
|
||||||
|
|
|
@ -126,10 +126,10 @@ void stestVectorString(uint& testnum, uint& testerr) {
|
||||||
MapPreOrder(loctestnum, loctesterr, vec, true, &MapStringAppend, string("!"));
|
MapPreOrder(loctestnum, loctesterr, vec, true, &MapStringAppend, string("!"));
|
||||||
NonEqualVector(loctestnum, loctesterr, vec, copvec, true);
|
NonEqualVector(loctestnum, loctesterr, vec, copvec, true);
|
||||||
|
|
||||||
copvec = std::move(vec);
|
copvec = move(vec);
|
||||||
FoldPreOrder(loctestnum, loctesterr, copvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A !B !"));
|
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 "));
|
FoldPreOrder(loctestnum, loctesterr, movvec, true, &FoldStringConcatenate, string(""), string("?"), string("?A B "));
|
||||||
SetAt(loctestnum, loctesterr, vec, false, 1, string(""));
|
SetAt(loctestnum, loctesterr, vec, false, 1, string(""));
|
||||||
vec.Resize(1);
|
vec.Resize(1);
|
||||||
|
@ -217,11 +217,11 @@ void stestListInt(uint& testnum, uint& testerr) {
|
||||||
|
|
||||||
RemoveFromFront(loctestnum, loctesterr, coplst, true);
|
RemoveFromFront(loctestnum, loctesterr, coplst, true);
|
||||||
FrontNRemove(loctestnum, loctesterr, coplst, true, 6);
|
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, lst, true, &FoldAdd<int>, 0, 0, 11);
|
||||||
FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldAdd<int>, 0, 0, 17);
|
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);
|
MapPreOrder(loctestnum, loctesterr, movlst, true, &MapIncrement<int>, 0);
|
||||||
FoldPreOrder(loctestnum, loctesterr, movlst, true, &FoldAdd<int>, 0, 0, 14);
|
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"));
|
InsertAtFront(loctestnum, loctesterr, lst, true, string("C"));
|
||||||
NonEqualList(loctestnum, loctesterr, lst, coplst, true);
|
NonEqualList(loctestnum, loctesterr, lst, coplst, true);
|
||||||
|
|
||||||
coplst = std::move(lst);
|
coplst = move(lst);
|
||||||
FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldStringConcatenate, string(""), string("?"), string("?CB A"));
|
FoldPreOrder(loctestnum, loctesterr, coplst, true, &FoldStringConcatenate, string(""), string("?"), string("?CB A"));
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
loctestnum++; loctesterr++;
|
loctestnum++; loctesterr++;
|
||||||
|
|
|
@ -52,12 +52,12 @@ void stestStackInt(Stk& stk, uint& testnum, uint& testerr) {
|
||||||
NonEqualStack(loctestnum, loctesterr, stk, copstk, true);
|
NonEqualStack(loctestnum, loctesterr, stk, copstk, true);
|
||||||
|
|
||||||
Top(loctestnum, loctesterr, copstk, true, 6);
|
Top(loctestnum, loctesterr, copstk, true, 6);
|
||||||
copstk = std::move(stk);
|
copstk = move(stk);
|
||||||
TopNPop(loctestnum, loctesterr, copstk, true, 5);
|
TopNPop(loctestnum, loctesterr, copstk, true, 5);
|
||||||
Pop(loctestnum, loctesterr, copstk, true);
|
Pop(loctestnum, loctesterr, copstk, true);
|
||||||
Top(loctestnum, loctesterr, copstk, true, 3);
|
Top(loctestnum, loctesterr, copstk, true, 3);
|
||||||
|
|
||||||
Stk movstk(std::move(stk));
|
Stk movstk(move(stk));
|
||||||
Top(loctestnum, loctesterr, stk, false, 0);
|
Top(loctestnum, loctesterr, stk, false, 0);
|
||||||
|
|
||||||
movstk.Clear();
|
movstk.Clear();
|
||||||
|
@ -218,12 +218,12 @@ void stestQueueInt(Que& que, uint& testnum, uint& testerr) {
|
||||||
NonEqualQueue(loctestnum, loctesterr, que, copque, true);
|
NonEqualQueue(loctestnum, loctesterr, que, copque, true);
|
||||||
|
|
||||||
Head(loctestnum, loctesterr, copque, true, 0);
|
Head(loctestnum, loctesterr, copque, true, 0);
|
||||||
copque = std::move(que);
|
copque = move(que);
|
||||||
HeadNDequeue(loctestnum, loctesterr, copque, true, 0);
|
HeadNDequeue(loctestnum, loctesterr, copque, true, 0);
|
||||||
Dequeue(loctestnum, loctesterr, copque, true);
|
Dequeue(loctestnum, loctesterr, copque, true);
|
||||||
Head(loctestnum, loctesterr, copque, true, 1);
|
Head(loctestnum, loctesterr, copque, true, 1);
|
||||||
|
|
||||||
Que movque(std::move(que));
|
Que movque(move(que));
|
||||||
Head(loctestnum, loctesterr, que, false, 0);
|
Head(loctestnum, loctesterr, que, false, 0);
|
||||||
|
|
||||||
movque.Clear();
|
movque.Clear();
|
||||||
|
@ -325,12 +325,12 @@ void stestQueueString(uint& testnum, uint& testerr) {
|
||||||
EnqueueM(loctestnum, loctesterr, quevec, string("A"));
|
EnqueueM(loctestnum, loctesterr, quevec, string("A"));
|
||||||
EnqueueM(loctestnum, loctesterr, quevec, string("B"));
|
EnqueueM(loctestnum, loctesterr, quevec, string("B"));
|
||||||
lasd::QueueVec<string> newquevec(vec);
|
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("A"));
|
||||||
EnqueueM(loctestnum, loctesterr, quelst, string("B"));
|
EnqueueM(loctestnum, loctesterr, quelst, string("B"));
|
||||||
lasd::QueueLst<string> newquelst(vec);
|
lasd::QueueLst<string> newquelst(vec);
|
||||||
EqualStack(loctestnum, loctesterr, quelst, newquelst, true);
|
EqualQueue(loctestnum, loctesterr, quelst, newquelst, true);
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
loctestnum++; loctesterr++;
|
loctestnum++; loctesterr++;
|
||||||
cout << endl << "Unmanaged error! " << endl;
|
cout << endl << "Unmanaged error! " << endl;
|
||||||
|
|
Loading…
Reference in New Issue