   UnitTest++: how to check if a Vector3 is 'close' to another
  Hi,I'm just writing a simple 3D vector class and have been writing some unit tests using UnitTest++ for it as I go. Up until now they've been fine written like this:TEST(AdditionOperator) {Vector3 lhs = Vector3(1.0f, 0.0f, 0.0f);Vector3 rhs = Vector3(0.0f, 0.0f, 1.0f);Vector3 expected = Vector3(1.0f, 0.0f, 1.0f);CHECK_EQUAL(expected, lhs + rhs);}But now in one of the tests I'm experiencing floating point inaccuracy and it's failing due to being ever so slightly out. I know there's the CHECK_CLOSE macro, but this relies on having <= and >= defined for the type you're checking, which I don't want to have to provide for Vector3 since it doesn't make a huge amount of sense. Even if I did this, I could see the situation where one component is slightly higher than expected and another is slightly lower, making it ambiguous as to which is less than the other.So, what should I do? Just use a CHECK with my own function close(Vector3, Vector3) as the condition (I don't like that because CHECK_EQUAL and CHECK CLOSE are meant for the job and report errors appropriately)? Use CHECK_CLOSE on each component of the vector (I don't like that since it'll result in a lot of redundant code)? Go ahead and implement some free functions for comparison of Vector3 specifically for the purpose of the tests?Any help will be much appreciated :) Thanks!   
  You could check if the dot product of the two vectors is close to the expected magnitude.   ;  Pick a very small epsilon value and subtract the vectors from each other. If the result is smaller than the epsilon, they are considered "close". Or calculate the distance between them and again specify a treshold it should be smaller than. Hope this helps.   ;  The problem with darkelf2k5's proposal is that it doesn't allow for larger errors at larger scales. For instance, (0,0,1) and (0,0,2) are quite different, but (0,0,1000000) and (0,0,1000001) are pretty much the same, although their differences are the same.Vector3 diff = v1 - v2;double perimeter = length(v1)+length(v2)+length(diff);double fraction_in_diff = length(diff) / perimeter;I would say the v1 and v2 are close iff fraction_in_diff is smaller than some threshold.;  Ok, so I'd CHECK whether a custom function says they're close. Thanks guys :)   