Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:33:41+00:00 2026-06-07T17:33:41+00:00

When testing some vector operations in my code I have to check for equality

  • 0

When testing some vector operations in my code I have to check for equality with some tolerance value because the float values may not be an exact match.

Which means that my test asserts are like this:

Assert.That(somevector.EqualWithinTolerance(new Vec3(0f, 1f, 0f)), Is.True);

Instead of this:

Assert.That(somevector, Is.EqualTo(new Vec3(0f, 1f, 0f)));

And that means that my exceptions are like this:

Expected: True
But was:  False

Instead of this:

Expected: 0 1 0
But was:  1 0 9,536743E-07

Making it slightly harder to understand what went wrong.

How do I use a custom comparison function and still get a nice exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:33:44+00:00Added an answer on June 7, 2026 at 5:33 pm

    Found the answer. NUnit EqualConstraint has a method with the expected name: Using.

    So I just added this class:

        /// <summary>
        /// Equality comparer with a tolerance equivalent to using the 'EqualWithTolerance' method
        /// 
        /// Note: since it's pretty much impossible to have working hash codes
        /// for a "fuzzy" comparer the GetHashCode method throws an exception.
        /// </summary>
        public class EqualityComparerWithTolerance : IEqualityComparer<Vec3>
        {
            private float tolerance;
    
            public EqualityComparerWithTolerance(float tolerance = MathFunctions.Epsilon)
            {
                this.tolerance = tolerance;
            }
    
            public bool Equals(Vec3 v1, Vec3 v2)
            {
                return v1.EqualWithinTolerance(v2, tolerance);
            }
    
            public int GetHashCode(Vec3 obj)
            {
                throw new NotImplementedException();
            }
        }
    

    I instantiated it and used it like this:

    Assert.That(somevector, Is.EqualTo(new Vec3(0f, 1f, 0f)).Using(fuzzyVectorComparer));
    

    It’s more typing, but it’s worth it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm testing some CRUD operations in Nhibernate. I have 3 tests in this
I am testing some Ruby code and have a failing Test::Unit::TestCase. Unfortunately, the failure
I have some concerns related to the fact of testing some functions containing the
I have just started out with testing some php mvc framework In it, it
I put a breakpoint in javascript and am testing some code with Chrome. I
I have a ASP.NET MVC site using Membership Provider. I have trouble testing some
I'm testing some legacy code that extends the default php exception object. This code
I was testing some code on the tryit editor and was unable to replicate
While testing some scripts, I've noticed, if expiration time is little (not zero) -
I was testing some of my code, in javascript I added .1+.2 and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.