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

Set helpers #isEqual, adds some test coverage #186

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.40.0

* Adding `#isEqual` to Set helpers (@mrflip). (provisional)

## 0.39.2

* Fixing typings of low-level structure consuming methods (@jerome-benoit).
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"lint": "eslint --cache ./*.js ./utils ./test",
"lint:fix": "eslint --cache --fix ./*.js ./utils ./test",
"prepublishOnly": "npm run lint && npm test && npm run test:types",
"prepublishOnly": "npm run lint && npm test && npm run test:types && echo 'Success! All checks passed!'",
"test": "mocha",
"test:types": "tsc --target es2015 --noEmit --noImplicitAny --noImplicitReturns ./test/types.ts"
},
Expand Down Expand Up @@ -80,6 +80,7 @@
"asciitree": "^1.0.2",
"damerau-levenshtein": "^1.0.7",
"eslint": "^8.2.0",
"eslint-plugin-mocha": "^10.1.0",
"leven": "^3.1.0",
"lodash": "^4.17.21",
"matcha": "^0.7.0",
Expand All @@ -90,14 +91,19 @@
"typescript": "^4.5.2"
},
"eslintConfig": {
"extends": "@yomguithereal/eslint-config",
"extends": [
"plugin:mocha/recommended",
"@yomguithereal/eslint-config"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"forOf": true
}
},
"rules": {
"mocha/no-identical-title": 0,
"mocha/no-setup-in-describe": 0,
"no-new": 0
}
}
Expand Down
27 changes: 27 additions & 0 deletions set.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,33 @@ exports.isSubset = function(A, B) {
return true;
};


/**
* Function returning whether A equals B (same size and B has all elements of A)
*
* @param {Set} A - First set.
* @param {Set} B - Second set.
* @return {boolean}
*/
exports.isEqual = function(A, B) {
var iterator = A.values(),
step;

// Shortcuts
if (A === B)
return true;

if (A.size !== B.size)
return false;

while ((step = iterator.next(), !step.done)) {
if (!B.has(step.value))
return false;
}

return true;
};

/**
* Function returning whether A is a superset of B.
*
Expand Down
8 changes: 4 additions & 4 deletions test/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('utils', function() {
describe('typed-arrays', function() {

describe('#.getPointerArray', function() {
var validatePointerArrayConstructor = function (min, max, expectedCtor) {
it(`returns ${expectedCtor} for ${min}`, () => {
var validatePointerArrayConstructor = function(min, max, expectedCtor) {
it(`returns ${expectedCtor} for ${min}`, function() {
assert.strictEqual(typed.getPointerArray(min), expectedCtor);
});
it(`returns ${expectedCtor} for ${(max - min) / 2}`, () => {
it(`returns ${expectedCtor} for ${(max - min) / 2}`, function() {
assert.strictEqual(typed.getPointerArray((max - min) / 2), expectedCtor);
});
it(`returns ${expectedCtor} for ${max}`, () => {
it(`returns ${expectedCtor} for ${max}`, function() {
assert.strictEqual(typed.getPointerArray(max), expectedCtor);
});
};
Expand Down
Loading