// =====================================================================================================================
// fennec-test, a program to execute unit tests for fennec
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// =====================================================================================================================
#ifndef FENNEC_TEST_H
#define FENNEC_TEST_H
#include
#include
#include
#include
#include
#include
namespace fennec
{
namespace test
{
template
inline std::ostream& operator<<(std::ostream& os, const vector& v)
{
os << "< ";
((os << v[IndicesV] << " "), ...);
os << ">";
return os;
}
template
inline std::ostream& operator<<(std::ostream& os, vector&& v)
{
os << "< ";
((os << v[IndicesV] << " "), ...);
os << ">";
return os;
}
template
inline std::ostream& operator<<(std::ostream& os, const matrix& m)
{
os << "[ ";
((os << m[ColIndicesV] << " "), ...);
os << " ]";
return os;
}
template
inline bool operator<=(const vector& lhs, const vector& rhs)
{
return fennec::all(fennec::lessThanEqual(lhs, rhs));
}
template
inline void __fennec_test_run(const std::string& expression, const ResultT result, const ResultT expected)
{
std::cout << std::boolalpha;
std::cout << '\t' << expression << " = " << result;
bool passed = false;
if constexpr(is_arithmetic_v or is_vector_v)
passed = fennec::abs(expected - result) <= numeric_limits::epsilon();
else
passed = result == expected;
if (not passed)
std::cout << ", expected " << expected;
std::cout << std::endl;
assert(passed);
}
}
}
#define fennec_test_run(Expression, Expected) __fennec_test_run(#Expression, Expression, Expected)
#define fennec_test_header(Header) std::cout << std::string(80, '=') << std::endl \
<< (Header) << std::endl \
<< std::string(80, '=') << std::endl
#define fennec_test_subheader(Header) std::cout << (Header) << ' ' << std::string(80 - sizeof(Header), '=') << std::endl
#define fennec_test_section(Section) std::cout << (Section) << ' ' << std::string(80 - sizeof(Section), '-') << std::endl
#define fennec_test_spacer(Count) std::cout << std::string(Count, std::cout.widen('\n'))
#endif // FENNEC_TEST_H