mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 3
Added template
This commit is contained in:
53
librerie/exercise3/zlasdtest/iterator/iterator.hpp
Normal file
53
librerie/exercise3/zlasdtest/iterator/iterator.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
#ifndef ITERATORTEST_HPP
|
||||
#define ITERATORTEST_HPP
|
||||
|
||||
#include "../../iterator/iterator.hpp"
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
template <typename Data>
|
||||
void GetItrValue(uint& testnum, uint& testerr, const lasd::Iterator<Data>& itr, bool chk, const Data& val) {
|
||||
bool tst;
|
||||
testnum++;
|
||||
try {
|
||||
std::cout << " " << testnum << " The value pointed by the iterator is \"" << *itr << "\": ";
|
||||
std::cout << ((tst = ((*itr == 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);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void SetItrValue(uint& testnum, uint& testerr, const lasd::Iterator<Data>& itr, bool chk, const Data& val) {
|
||||
bool tst;
|
||||
testnum++;
|
||||
try {
|
||||
std::cout << " " << testnum << " Setting the value pointed by the iterator to \"" << val << "\": ";
|
||||
*itr = val;
|
||||
std::cout << ((tst = ((*itr == 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);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void Terminated(uint& testnum, uint& testerr, const lasd::Iterator<Data>& itr, bool chk) {
|
||||
bool tst;
|
||||
testnum++;
|
||||
std::cout << " " << testnum << " The iterator is " << ((tst = itr.Terminated()) ? "" : "not ") << "terminated: ";
|
||||
std::cout << ((tst = (tst == chk)) ? "Correct" : "Error") << "!" << std::endl;
|
||||
testerr += (1 - (uint) tst);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user