Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
neoncitylights committed Jan 15, 2024
1 parent 8b34b6f commit 7bb3fbf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getDifference, getIntersection, getSymmetricDifference, getUnion } from './operations';
export { areSetsDisjoint, areSetsEqual, areSetsEquivalent, isProperSubsetOf, isProperSupersetOf, isSubsetOf, isSupersetOf } from './predicates';
export { areSetsDisjoint, areSetsEqual, areSetsEquivalent, containsAllElements, isProperSubsetOf, isProperSupersetOf, isSubsetOf, isSupersetOf } from './predicates';
export { getJaccardSimilarityCoefficient, getLogDice, getOverlapCoefficient, getSorensenDiceCoefficient } from './similarity';
export type { SetFunction, SetOperation, SetPredicate, SetSimilarity } from './types';
2 changes: 1 addition & 1 deletion src/predicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function isSupersetOf<TElement>(a: Set<TElement>, b: Set<TElement>): bool
* @param b - Set B of type `<TElement>` elements
* @returns Whether A contains all elements of B
*/
function containsAllElements<TElement>(a: Set<TElement>, b: Set<TElement>): boolean {
export function containsAllElements<TElement>(a: Set<TElement>, b: Set<TElement>): boolean {
for (const element of b) {
if (!a.has(element)) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions tests/predicates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ import {
areSetsDisjoint,
areSetsEqual,
areSetsEquivalent,
containsAllElements,
isProperSubsetOf,
isProperSupersetOf,
isSubsetOf,
isSupersetOf,
} from '../src';

describe('containsAllElements', () => {
test.each([
[[1, 2, 3], [1, 2], true],
[[1, 2, 3], [], true],
[[1, 2, 3], [4], false],
])('%O contains %O is %O', (a, b, expected) => {
expect(containsAllElements(
new Set(a),
new Set(b),
)).toBe(expected);
});
});

describe('areSetsDisjoint', () => {
test.each([
[true, [], []],
Expand Down
11 changes: 5 additions & 6 deletions tests/similarity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ import {
} from '../src';

describe('Jaccard\'s Similarity Coefficient', () => {

test.each([
['hello world', 'world hello', 1.0],
['', '', 1.0],
[[], [], 1],
[['hello', 'world'], ['world', 'hello'], 1],
])('comparing "%s" and "%s" will give a score of %f', (a, b, expected) => {
expect(getJaccardSimilarityCoefficient(
new Set(a.split(' ')),
new Set(b.split(' ')),
new Set(a),
new Set(b),
)).toBeCloseTo(expected);
});
});

describe('Pavel Rychlý\'s LogDice', () => {
test.each([
['hello world', 'world hello'],
['', ''],
['hello world', 'world hello'],
])('comparing "%s" and "%s" will give 14 for full similarity', (a, b) => {
expect(getLogDice(
new Set(a.split(' ')),
Expand Down

0 comments on commit 7bb3fbf

Please sign in to comment.