Add test for floorMultiple/ceilMultiple (float only)

This commit is contained in:
Sebastian Rettenberger 2015-09-23 12:03:44 +02:00
parent de9e62f0a4
commit fa6fd748c0

View File

@ -31,6 +31,7 @@
#include <glm/gtc/round.hpp> #include <glm/gtc/round.hpp>
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <glm/gtc/vec1.hpp> #include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
#include <vector> #include <vector>
#include <ctime> #include <ctime>
#include <cstdio> #include <cstdio>
@ -293,6 +294,86 @@ namespace ceilPowerOfTwo
} }
}//namespace ceilPowerOfTwo }//namespace ceilPowerOfTwo
namespace floorMultiple
{
template <typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.3, 0.0001},
{-1.4, 0.3, -1.5, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::floorMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_float();
return Error;
}
}//namespace floorMultiple
namespace ceilMultiple
{
template <typename genType>
struct type
{
genType Source;
genType Multiple;
genType Return;
genType Epsilon;
};
int test_float()
{
type<glm::float64> const Data[] =
{
{3.4, 0.3, 3.6, 0.0001},
{-1.4, 0.3, -1.2, 0.0001},
};
int Error(0);
for(std::size_t i = 0, n = sizeof(Data) / sizeof(type<glm::float64>); i < n; ++i)
{
glm::float64 Result = glm::ceilMultiple(Data[i].Source, Data[i].Multiple);
Error += glm::epsilonEqual(Data[i].Return, Result, Data[i].Epsilon) ? 0 : 1;
}
return Error;
}
int test()
{
int Error(0);
Error += test_float();
return Error;
}
}//namespace ceilMultiple
int main() int main()
{ {
int Error(0); int Error(0);
@ -304,5 +385,8 @@ int main()
Error += ceilPowerOfTwo::perf(); Error += ceilPowerOfTwo::perf();
# endif//NDEBUG # endif//NDEBUG
Error += floorMultiple::test();
Error += ceilMultiple::test();
return Error; return Error;
} }