Skip to content

Commit

Permalink
#2: Add support for multiple elements to be added at once
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbulman committed Jan 9, 2021
1 parent 25c4ac4 commit 0987d70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/AdvancedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class AdvancedSet<T> {
return this._set.has(val);
}

public add(val: T): AdvancedSet<T> {
this._set.add(val);
public add(...vals: T[]): AdvancedSet<T> {
for (const val of vals) this._set.add(val);
return this;
}

Expand Down Expand Up @@ -120,6 +120,6 @@ export default class AdvancedSet<T> {
return this.intersection(setB).isEmpty();
}

// partialSubset, isProperSubsetOf, isProperSupersetOf, multi set intersection,
// isProperSubsetOf, isProperSupersetOf, multi set intersection,
// power sets, subset by function
}
21 changes: 21 additions & 0 deletions src/__tests__/Add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import AdvancedSet from '../AdvancedSet';

test('Add nothing to empty set should be empty set', () => {
expect(new AdvancedSet().add().toArray()).toMatchObject([]);
});

test('Empty set adding a value should be a set with just that value', () => {
expect(new AdvancedSet().add(1).toArray()).toMatchObject([1]);
});

test('Non emtpy set adding a value should be the set with the new value', () => {
expect(new AdvancedSet(2, 3).add(1).toArray().sort()).toMatchObject([1, 2, 3].sort());
});

test('Non empty set adding nothing should be just that set', () => {
expect(new AdvancedSet(4, 5).add().toArray().sort()).toMatchObject([4, 5].sort());
});

test('Advanced sets should allow for multiple items to be added at the same time', () => {
expect(new AdvancedSet(2, 3, 5).add(1, 4).toArray().sort()).toMatchObject([1, 2, 3, 4, 5].sort());
});

0 comments on commit 0987d70

Please sign in to comment.