#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