Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power sets are broken for ES6 #50

Closed
michaelmior opened this issue Sep 16, 2020 · 5 comments
Closed

Power sets are broken for ES6 #50

michaelmior opened this issue Sep 16, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@michaelmior
Copy link
Collaborator

Describe the bug
The power set function is broken in ES6 (at least, as transformed via Babel).

To Reproduce

$ cat .babelrc
{
  "presets": ["@babel/preset-env"]
}
$ babel-node
babel > require('set-extensions');
{}
babel > Set.power(new Set([1,2,3]));
Set(8) {
  Set(1) { 3 },
  Set(2) { 3, 2 },
  Set(2) { 3, 1 },
  Set(3) { 3, 2, 1 },
  Set(0) {},
  Set(1) { 1 },
  Set(1) { 2 },
  Set(1) { 3 }
}

Expected behavior
The set {2, 1} should be included in the power set.

Desktop (please complete the following information):

  • OS: macOS Catalina 10.15.6
  • Browser: node.js
  • Version: v14.8.0

Additional context

  • babel-node version: 7.8.4
  • set-extensions version: 1.4.1
  • @babel/core version: 7.11.6
  • @babel/preset-env version: 7.11.5
@jankapunkt
Copy link
Owner

hi @michaelmior thank you for the bug report. I will investigate and will use this as a chance to revive this package.

@jankapunkt jankapunkt added the bug Something isn't working label Sep 17, 2020
@jankapunkt
Copy link
Owner

This revealed another bug in Set.prototype.equal, where

Set {
  Set { 1, 2, 3 },
  Set { 1, 2 },
  Set { 1, 3 },
  Set { 2, 3 },
  Set { 1 },
  Set { 2 },
  Set { 3 },
  Set {}
}

and

Set {
  Set { 3 },
  Set { 3, 2 },
  Set { 3, 1 },
  Set { 3, 2, 1 },
  Set {},
  Set { 1 },
  Set { 2 },
  Set { 3 }
}

are evualuated as equal, while in fact they are not.

@jankapunkt
Copy link
Owner

jankapunkt commented Sep 17, 2020

Another bug is that there should be no doubled entries of Set { 3 }. It is right to assume, that these are two totally different instances and therefore pass the checks but their absolute value representation are the same (Set { 3 } should be considered equal to Set { 3 }). So the Set.prototype.has function is also involved here.

The has function is not involved, as it works correct. The add function is rather affected:

const set = (...args) => new Set(args)

const set1 = set(3)
const set2 = set(3)

const set3 = set()
set3.add(set1)
set3.has(set1) // true
set3.has(set2) // true

set3.add(set2) // should skip set2
set3 // Set { Set { 3 }, Set { 3 } }

@jankapunkt jankapunkt mentioned this issue Sep 17, 2020
@jankapunkt
Copy link
Owner

@michaelmior I added you as collaborator. If you accept I can assign you to review the PR #51 which attempts to fix the issue.

@jankapunkt
Copy link
Owner

Implemented, via #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants