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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:35:18+00:00 2026-06-15T14:35:18+00:00

I have been testing my code with Specs2 for some time now and in

  • 0

I have been testing my code with Specs2 for some time now and in my test I wanted to ensure that two objects of some type compare correctly:

"compare based on carrier value" in {
  val b0 = new BitField32(343948)
  val b0prim = new BitField32(343948)
  val b1 = new BitField32(112)

  b0prim should be equalTo(b0)
  b1 should not be equalTo(b0)
}

When this test was executed, I got an error

[error] x compare based on carrier value
[error]    'core.BitField32@17805bd5' is not equal to 'core.BitField32@6c0d0900' (BitField32Spec.scala:34)
[error] Expected: ...ld32@[6c0d0900]
[error] Actual:   ...ld32@[17805bd5]

Which seemed reasonable, since my class didn’t have any methods for comparison. So I tried a couple of things that came to mind: implementing Ordered and providing a variety of comparison methods:

/**
 * mutable 32bit Bitfield
 */
class BitField32(var carrier: Int) extends Ordered[BitField32]{

  override def equals(that: Any) = true
  def canEqual(that: Any) = true

  def compare(that: BitField32) = this.carrier - that.carrier
  def ===(that: BitField32) = this.carrier == that.carrier
  def ==(that: BitField32) = this.carrier == that.carrier
  //(...)
}

But I still keep getting the same error. I tried to read specs2 sources to see how the equalTo matcher works, but I wasn’t any wiser afterwards.

Any idea how I have to modify my class for the equality to be picked up by (stock) specs2 matchers?

BitField32 isn’t a case class by design – I want it to be mutable.

  • 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-15T14:35:19+00:00Added an answer on June 15, 2026 at 2:35 pm

    I actually misread the error message after adding the comparison methods: it was saying that compared objects were equal, even though they shouldn’t have been. The comparison used by specs2 was in place and it was always returning true – the equals method. Here is the fixed code:

    class BitField32(var carrier: Int){
    
      override def equals(that: Any) = that match {
        case bf: BitField32 => this == bf
        case _ => false
      }
    
      def ==(that: BitField32) = this.carrier == that.carrier
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been testing out some code and I need to load day view
I have been told that Singletons are hard to test. http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/ I have
I have been doing some testing with CSV.table . I have two small and
I have been testing my code to save into an XML file locally and
In the following code, where would I use preventDefault ? I have been testing
I can't push my code to my domain and have been testing up until
I have been doing some testing on the Random class and I have used
Since the iOS 5 Betas I have been testing my app's code and the
So, i've been working for some time at a phonegap+jqm application. I've been testing
I have been testing the jQuery .html() function and I have found that 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.