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 6342809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:18:52+00:00 2026-05-24T20:18:52+00:00

Scope: Using Google Test and OpenCV. I’d like to test that my Vec3f equals

  • 0

Scope: Using Google Test and OpenCV.

I’d like to test that my Vec3f equals another Vec3f. Vec3f is a vector in OpenCV of dimension 3 and type float. The ==-operator is defined, so EXPECT_EQ(Vec3f(), Vec3f()) works.

But as they are floats, I’d like to use the EXPECT_NEAR(float a, float b, float delta) macro. What can I do so that I can use it like EXPECT_NEAR(vec_a, vec_b, float delta)?

At the moment I am looping through each element of the vector and doing an EXPECT_NEAR there.

This might be related: Convenient method in GoogleTest for a double comparison of not equal?

  • 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-05-24T20:18:53+00:00Added an answer on May 24, 2026 at 8:18 pm

    You are doing basically the correct thing. However, I would use a custom assertion function like:

    ::testing::AssertionResult AreAllElementsInVectorNear(const Vec3f& a, const Vect3f& b, float delta) {
      if ([MAGIC])
        return ::testing::AssertionSuccess();
      else
        return ::testing::AssertionFailure() << "Vectors differ by more than " << delta;
    }
    

    MAGIC would then include your code to e.g. compare if both vectors have the same size, followed by iterating over all elements and mutually check if the elements at the same index differ by no more than the delta. Note that the code assumes that the << operator is provided for Vec3f.

    The function then is used:

    EXPECT_TRUE(AreAllElementsInVectorNear(a, b, 0.1))
    

    If the expect fails the output might be:

    Value of: AreAllElementsInVectorNear(a, b, 0.1)
      Actual: false (Vectors differ by more then 0.1)
    Expected: true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with getting a named scope working using using an attribute of
When using Validates_uniqueness_of with the :scope option, is it valid to pass an array
I'm using Ryan Bates' excellent scope_builder to conditionally build a new named scope to
I'm using System.Transactions and Transaction scope for my transaction handling in conjunction with the
Using instance methods as callbacks for event handlers changes the scope of this from
I am looking for an alternative to using an object/variable in global scope --
I am trying to post some content to my google buzz account using google
I've been using http://code.google.com/p/plblocks/ for a while now to get blocks support in our
I am using OAuth to access Google's API (IMAP, contacts, etc), assuming I have
I'm developing a small python like language using flex, byacc (for lexical and parsing)

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.