question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling of duplicates when comparing sets

See original GitHub issue

Current behaviour is that

[3,1,2,3].should.have.deep.members([3,2,1]);      
[1,2,3].should.have.deep.members([3,2,1,3]);
[1,2,3].should.deep.include.members([3,2,1,3]);
chai.assert.sameDeepMembers([1,2,3],[3,2,1,3]);

all pass. The documentation uses language of “sets” not “multisets” so it is hard to judge what should be the good behaviour when the arguments contain duplicates. One could argue that current implementation of should.deep.include.members is consistent with the documentation, as indeed every element of [3,2,1,3] belongs to [1,2,3]. Similarly, one could argue similarly for should.have.deep.members. But in practice I found myself in situations where what I really want to test is if the actual is a permutation of expected. There are many situations in which an order in the array cannot be guaranteed (say, Object.keys(obj)).

The issue might seem not so controversial when the arguments are written as literals and one can easily see what is the problem. But in a more realistic scenarios like:

emittedEvents.should.have.deep.members(expectedEvents)

one could easily be fooled into thinking that this assertion simply means “expectedEvents is a permutation of expectedEvents” only to be surprised that firing the same event twice does not violate this test. Similarly one could have something like:

sorted.should.have.deep.members(inputArray)

and never spot an error in the implementation which caused removal of duplicates.

Perhaps it would be a good thing to have a separate should.be.permutation.of assertion for that case. But care must be taken to redact documentation for the other assertions so they do not suggest wrongly that they could be used for that.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
meebercommented, Jun 24, 2016

I plan on tackling this one this weekend.

1reaction
meebercommented, Apr 29, 2016

@lucasfcosta: Good point. I agree.

Edit: What are your thoughts on this as a bug to be fixed soon, or a breaking change for 4.x.x? I’m slightly leaning toward breaking change, mainly because it doesn’t feel urgent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easily Compare Duplicate Values in Excel - TeachExcel.com
Here, I'll show you a simple technique to quickly and easily compare large lists of duplicate values. This allows you to analyze the...
Read more >
Comparing two data sets with duplicate entries
Hello, I am trying to compare data from 1 data set with another but running into some difficulty as there are duplicates in...
Read more >
Comparing duplicates between two data sets and using a ...
I'd like to scan and compare column A and D , and look for duplicates. If there are duplicates, I'd like to find...
Read more >
Find duplicates and compare two lists in Microsoft Excel by ...
Here's an Excel function to highlight duplicates. To compare two lists in Microsft Excel, to find duplicates, you can use either conditional ...
Read more >
Compare Two Sheets for Duplicates with Conditional Formatting
In this video, I demonstrate how to compare two worksheets and use conditional formatting to highlight entries that are found in both.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found