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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:02:54+00:00 2026-05-31T01:02:54+00:00

Say I want to assert that two structs are equivalent: // Using CGPoint here

  • 0

Say I want to assert that two structs are equivalent:

// Using CGPoint here for brevity, but my question applies to any struct type
CGPoint a = CGPointMake(1, 2);
CGPoint b = CGPointMake(1, 2);
STAssertEquals(a, b, @"this works");
assertThat(a, equalTo(b));

Is there no way to write an assertion using Hamcrest that works like the STAssertEquals above? The assertThat line fails to compile as the macros expect id parameters, which structs are not. I tried variations of the equalTo matcher, such as sameInstance, but they all seem to require id typed parameters. Next, I thought a good workaround would be to assert that an arbitrary expression has a YES or NO value. Something like this:

assertThat(a == b);

or this:

assertThat(a == b, isTrue());

But I don’t see anything like this in Hamcrest.

Am I am missing something obvious? Clearly I can accomplish what I want to do by using the SenTest macros such as STAssertEquals, but I had expected it to be simple to implement these assertions using Hamcrest, so that all my assertions have a consistent style.

I also know that I can do this by implementing a custom Hamcrest matcher for the particular structs I am comparing. But I was really looking for a simple assertion/matcher that can just compare any C structs for simple bytewise equality.

Perhaps it’s simply the case that none of the possibilities I have mentioned are possible out of the box with Hamcrest. If that’s true, I’ll accept a convincing explanation to this effect as the Answer.

Thanks

  • 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-31T01:02:55+00:00Added an answer on May 31, 2026 at 1:02 am

    OCHamcrest is designed to check objects for matches, so assertThat takes an argument as the first parameter (and a matcher as the second).

    There is limited support for scalars. For example, you can say

    assertThatInteger(a, equalToInteger(b));
    

    A change has been sent to me for an NSValue matcher, but I haven’t had time to review it yet. It opens the door to NSPoint, NSSize, etc. But still, scalar support in OCHamcrest is a workaround.

    For your own structs, I’d use STAssertEquals. The problem is that it’s an all-or-nothing equality comparison, which may make your tests brittle. If that happens, it would be nicer to write your own custom matcher that supports per-field matching. (I’ll try to make the NSValue matcher something you can subclass.)

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

Sidebar

Related Questions

Say I want to have a method that takes any kind of number, is
Say I want to get the HTML of http://www.google.com as a String using some
say I want to scaffold generate university but university should eventually be related to
I have a question concerning unit testing. Let's say that I have several classes
Let's say I am using a framework that has a class called Animal. class
Beginner rails/javascript question: Let's say that I have a simple Circle model in a
Say you want a simple maze on an N by M grid, with one
Say you want to generate a matched list of identifiers and strings enum {
Say I want to copy the contents of a directory excluding files and folders
Say I want to create vb.net application in Visual studio 2005. What is the

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.