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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:34:41+00:00 2026-05-31T15:34:41+00:00

I am looking for a test routine like is_deeply in Test::More . There’s cmp_bag

  • 0

I am looking for a test routine like is_deeply in Test::More.
There’s cmp_bag from Test::Deep but this only operates on the array itself, not the horribly large hash-of-arrays-of-hashes data structure I’m passing in. Is there something like:

is_deeply $got, $expected, {
    array => cmp_bag,
    # and other configuration...
}, "Ugly data structure should be the same, barring array order.";

Clarification

I could recursively delve into my $expected and $got objects and convert the arrays into bag objects:

sub bagIt {
    my $obj = shift;
    switch (ref($obj)) {
        case "ARRAY"    {
            return bag([
                map { $_ = bagIt($_) }
                @$obj
            ]);
        } case "HASH"   {
            return {
                map { $_ => bagIt( $obj->{$_} ) }
                keys %$obj
            };
        } else {
            return $obj;
        }
    }
}

I’m wondering if there is a way to tell some variant of is_deeply to do this for me.

  • 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-31T15:34:42+00:00Added an answer on May 31, 2026 at 3:34 pm

    Looks like there isn’t an option in Test::Deep or other Test::* packages to treat each array as a bag-set. The following function works, but is not efficient for testing over large data structures:

    sub bagIt {
        my $obj = shift;
        my $ref = ref($obj);
        if ($ref eq 'ARRAY') {
            return Test::Deep::bag(
                map { $_ = bagIt($_) }
                @$obj
            );  
        } elsif ($ref eq 'HASH') {
            return {
                map { $_ => bagIt( $obj->{$_} ) } 
                keys %$obj
            };  
        } else {
            return $obj;
        }   
    }
    

    In the end, I ended up refactoring my code to not depend upon such a course-grained test.

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

Sidebar

Related Questions

I've successfully built SDL from source using bcc 5.5.1 but any SDL test application
Problem If the text in TRichEdit is something like this; 'hello, world'#$D#$A Then the
I'm looking to test some code I've written and to do so I need
I am looking to set test parameters into my variables that I have written,
I'm looking for a test framework for C++ in Eclipse CDT. Ideally it should
I'm calling this linear class relationship , but correct me if I'm wrong. I'm
I am writing an init.d script and am looking to test if a returned
I'm on a mac and I'm looking to test multiple sizes for multiple browsers.
I have been browsing these iOS Cocoa controls and looking to test out a
I have googled around and played around with test scripts (powershell/spec/nunit/msbuild). I am looking

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.