A vector is out by 0.000000001f so the test is failing.
Doing the logic in my head yeilds -1.0f, -1.0f but when I wrote the code to pass the test (Using the built in Vector methods) the answer comes back as -0.999999999f, -0.999999999f which is still 'right'.
This is C# (Vector2 class provided by the XNA framework) by the way, so I tried adding an epsilon value to each the x and y parameter of the Vector but this didn't work.
The way I see it is that by coding the answer, I'm writing the production code. E.g. it would be the same. Surely this is not the right.
Any advice?
Unit testing frameworks usually provide asserts for floats that take a precision. For example in Visual Studio Test you can write:
Assert.AreEqual(1.0f, 0.9999999999f, 1e-3); // passes
Assert.AreEqual(1.0f, 0.9f, 1e-3); // fails
Please see my answer here.
It is not about C#, but the same logic applies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With