libcruft-util/test/kmeans.cpp
Danny Robson f6056153e3 rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace
as the extended library code.
2018-08-05 14:42:02 +10:00

35 lines
842 B
C++

#include "tap.hpp"
#include "kmeans.hpp"
#include "point.hpp"
///////////////////////////////////////////////////////////////////////////////
int
main ()
{
cruft::TAP::logger tap;
// create one point and check it 'converges' to this one point
{
const std::array<cruft::point3f,1> p { {{1,2,3}} };
std::array<cruft::point3f,1> q;
cruft::kmeans (cruft::view{p}, cruft::view{q});
tap.expect_eq (p, q, "single point, single k");
}
// create two vectors, check if the mean converges to their average
{
const std::array<cruft::vector3f,2> p {{
{1}, {2}
}};
std::array<cruft::vector3f,1> q;
cruft::kmeans (cruft::view{p}, cruft::view{q});
tap.expect_eq (q[0], (p[0]+p[1])/2, "two point, single k");
}
return tap.status ();
}