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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:56+00:00 2026-05-26T09:05:56+00:00

I have a test which fails intermittently because of ordering issues when I iterate

  • 0

I have a test which fails intermittently because of ordering issues when I iterate over the values in a Map.

Scala helpfully provides a ListMap which makes the tests stable, at the expense of performance. So I abstracted the ImmutableMapFactory as a val and use it in my code.

class C {
  val immutableMapFactory = scala.collection.immutable.Map

  def func = {
    ...
    immutableMapFactory(pairs :_*)
  }
}

Now my plan was to extend C and override immutableMapFactory for tests

class TestableC extends C {
  override val immutableMapFactory = scala.collection.immutable.ListMap
}

Unsurprising this fails as ListMap does not have the same type as Map. How should I specify the type of the val (or a def) so that I can use the factory wherever I need to create a Map?

  • 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-26T09:05:57+00:00Added an answer on May 26, 2026 at 9:05 am

    Your problem is in this line:

    val immutableMapFactory = scala.collection.immutable.Map
    

    This makes immutableMapFactory equal to the singleton object Map. ListMap (the singleton) is not a subclass of Map (the singleton), so the subsequent override fails.

    If you instead take the apply method from Map, and partially apply it to form a first class function (of type (A, B)* => immutable.Map[A,B]) then the technique can be made to work:

    import collection.immutable
    
    class Bip {
      def fac[A,B] = immutable.Map.apply[A,B] _
    }
    
    class Bop extends Bip {
      override def fac[A,B] = immutable.ListMap.apply[A,B] _
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following test using NMock which fails. It used to work when
I have this test: def test_should_only_list_promoted_on_index get :index assert_equal stories(:promoted), assigns(:stories) end which fails
Using RSpec and Cancan, I have this test which fails with: Failure/Error: User.should_receive(:new).and_return(@user) expected:
I have the following test which seems to produce same strings but Assert.AreEqual fails.
I have a test which randomly fails and I want to let it retry
I have a test which runs great on my development MacBook Pro, but fails
I have a test which looks a bit like this (I'm simplifying a bit
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have a Nunit test which adds message into MSMQ. In the teardown of
I have a Boost unit test case which causes the object under test to

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.