Yomguithereal / mnemonist

Curated collection of data structures for the JavaScript/TypeScript language.
https://yomguithereal.github.io/mnemonist
MIT License
2.26k stars 92 forks source link

Set helpers #isEqual, adds some test coverage #186

Open mrflip opened 2 years ago

mrflip commented 2 years ago

Addresses #172

Implementation is that two sets are isEqual if they are the same object, or have the same size and B has every element of A.

I did this by duplicating the entire isSubset method and changing the relevant line, rather than first testing for size equality and then delegating to isSubset -- saving operations at the cost of code complexity.

Also have added some test coverage in there. They are largely documentary in that they cover edge cases unlikely to crop up in the current implementation, but which a naïve outsider might like reassurance about (eg that intersecting with an empty set makes an empty set, etc)

Once I've addressed your comments, I can do the same to everything else with isSubset and for other tests.

mrflip commented 2 years ago

I believe I've caught all the test style violations.