#ifndef BSTTEST_HPP #define BSTTEST_HPP #include "../../bst/bst.hpp" /* ************************************************************************** */ template void EqualBST(uint& testnum, uint& testerr, const lasd::BST& bst1, const lasd::BST& bst2) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") The two bsts are " << ((tst = (bst1 == bst2)) ? "" : "not ") << "equal: "; std::cout << (tst ? "Correct" : "Error") << "!" << std::endl; } catch(std::exception exc) { tst = false; std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; } testerr += (1 - (uint) tst); } template void NonEqualBST(uint& testnum, uint& testerr, const lasd::BST& bst1, const lasd::BST& bst2) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") The two bsts are " << ((tst = (bst1 != bst2)) ? "not " : "") << "equal: "; std::cout << (tst ? "Correct" : "Error") << "!" << std::endl; } catch(std::exception exc) { tst = false; std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; } testerr += (1 - (uint) tst); } /* ************************************************************************** */ template void InsertC(uint& testnum, uint& testerr, lasd::BST& bst, const Data& val) { testnum++; bool tst = true; try { std::cout << " " << testnum << " (" << testerr << ") Insertion in the bst of the value \"" << val << "\": "; bst.Insert(val); std::cout << "Correct!" << std::endl; } catch(std::exception exc) { tst = false; std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; } testerr += (1 - (uint) tst); } template void InsertM(uint& testnum, uint& testerr, lasd::BST& bst, const Data& val) { testnum++; bool tst = true; try { std::cout << " " << testnum << " (" << testerr << ") Insertion in the bst of the value \"" << val << "\": "; bst.Insert(std::move(val)); std::cout << "Correct!" << std::endl; } catch(std::exception exc) { tst = false; std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; } testerr += (1 - (uint) tst); } template void Remove(uint& testnum, uint& testerr, lasd::BST& bst, const Data& val) { testnum++; bool tst = true; try { std::cout << " " << testnum << " (" << testerr << ") Removal from the bst of the value \"" << val << "\": "; bst.Remove(val); std::cout << "Correct!" << std::endl; } catch(std::exception exc) { tst = false; std::cout << "\"" << exc.what() << "\": " << "Error!" << std::endl; } testerr += (1 - (uint) tst); } template void Min(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Min of the bst with value \"" << bst.Min() << "\": "; std::cout << ((tst = ((bst.Min() == 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 RemoveMin(uint& testnum, uint& testerr, lasd::BST& bst, bool chk) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove min from the the bst: "; bst.RemoveMin(); 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 MinNRemove(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") MinNRemove from the bst with value \"" << bst.Min() << "\": "; std::cout << ((tst = ((bst.MinNRemove() == 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 Max(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Max of the bst with value \"" << bst.Max() << "\": "; std::cout << ((tst = ((bst.Max() == 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 RemoveMax(uint& testnum, uint& testerr, lasd::BST& bst, bool chk) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove max from the the bst: "; bst.RemoveMax(); 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 MaxNRemove(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") MaxNRemove from the bst with value \"" << bst.Max() << "\": "; std::cout << ((tst = ((bst.MaxNRemove() == 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 Predecessor(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Predecessor of " << prd << " with value \"" << bst.Predecessor(prd) << "\": "; std::cout << ((tst = ((bst.Predecessor(prd) == 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 RemovePredecessor(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove predecessor of " << prd << " from the the bst: \"" << bst.Predecessor(prd) << "\": "; bst.RemovePredecessor(prd); 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 PredecessorNRemove(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove predecessor of " << prd << " from the the bst: \"" << bst.Predecessor(prd) << "\": "; std::cout << ((tst = ((bst.PredecessorNRemove(prd) == 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 Successor(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Successor of " << prd << " with value \"" << bst.Successor(prd) << "\": "; std::cout << ((tst = ((bst.Successor(prd) == 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 RemoveSuccessor(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove successor of " << prd << " from the the bst: \"" << bst.Successor(prd) << "\": "; bst.RemoveSuccessor(prd); 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 SuccessorNRemove(uint& testnum, uint& testerr, lasd::BST& bst, bool chk, const Data& prd, const Data& val) { bool tst; testnum++; try { std::cout << " " << testnum << " (" << testerr << ") Remove successor of " << prd << " from the the bst: \"" << bst.Successor(prd) << "\": "; std::cout << ((tst = ((bst.SuccessorNRemove(prd) == 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); } /* ************************************************************************** */ #endif