-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(primitives): add new set methods and tests for reatomSet (#866)
* feat(primitives): add new set methods and tests for reatomSet * feat(primitives): rename set method from swtich to toggle * feat(primitives): delete useless new Set * feat(primitives): add types for set proposal, fix test for reatomSet.isDisjointFrom * feat(primitives): add core js for set tests * chore: fix ProposalSet --------- Co-authored-by: Arutiunian Artem <[email protected]>
- Loading branch information
Showing
5 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import 'core-js/proposals/set-methods-v2' | ||
|
||
import { createCtx } from '@reatom/core' | ||
import { suite } from 'uvu' | ||
import * as assert from 'uvu/assert' | ||
|
||
import { reatomSet } from './reatomSet' | ||
|
||
const test = suite('reatomSet') | ||
|
||
test(`reatomSet. init`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal(ctx.get(reatomSet(new Set([1, 2, 3]))), new Set([1, 2, 3])) | ||
}) | ||
|
||
test(`reatomSet. add`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal(reatomSet(new Set([1, 2, 3])).add(ctx, 4), new Set([1, 2, 3, 4])) | ||
}) | ||
|
||
test(`reatomSet. delete`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal(reatomSet(new Set([1, 2, 3])).delete(ctx, 3), new Set([1, 2])) | ||
}) | ||
|
||
test(`reatomSet. toggle`, () => { | ||
const ctx = createCtx() | ||
const a = reatomSet(new Set([1, 2, 3])) | ||
|
||
assert.equal(a.toggle(ctx, 3), new Set([1, 2])) | ||
assert.equal(a.toggle(ctx, 3), new Set([1, 2, 3])) | ||
}) | ||
|
||
test(`reatomSet. clear`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal(reatomSet(new Set([1, 2, 3])).clear(ctx), new Set()) | ||
}) | ||
|
||
test(`reatomSet. reset`, () => { | ||
const ctx = createCtx() | ||
const a = reatomSet(new Set([1, 2, 3])) | ||
|
||
assert.equal(a.add(ctx, 4), new Set([1, 2, 3, 4])) | ||
assert.equal(a.reset(ctx), new Set([1, 2, 3])) | ||
}) | ||
|
||
test(`reatomSet. intersection`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).intersection(ctx, new Set([2, 3, 4])), | ||
new Set([2, 3]), | ||
) | ||
}) | ||
|
||
test(`reatomSet. union`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).union(ctx, new Set([2, 3, 4])), | ||
new Set([1, 2, 3, 4]), | ||
) | ||
}) | ||
|
||
test(`reatomSet. difference`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).difference(ctx, new Set([2, 3, 4])), | ||
new Set([1]), | ||
) | ||
}) | ||
|
||
test(`reatomSet. symmetricDifference`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).symmetricDifference(ctx, new Set([2, 3, 4])), | ||
new Set([1, 4]), | ||
) | ||
}) | ||
|
||
test(`reatomSet. isSubsetOf`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isSubsetOf(ctx, new Set([2, 3, 4])), | ||
false, | ||
) | ||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isSubsetOf(ctx, new Set([1, 2, 3])), | ||
true, | ||
) | ||
}) | ||
|
||
test(`reatomSet. isSupersetOf`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isSupersetOf(ctx, new Set([2, 3, 4])), | ||
false, | ||
) | ||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isSupersetOf(ctx, new Set([1, 2, 3])), | ||
true, | ||
) | ||
}) | ||
|
||
test(`reatomSet. isDisjointFrom`, () => { | ||
const ctx = createCtx() | ||
|
||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isDisjointFrom(ctx, new Set([4, 5, 6])), | ||
true, | ||
) | ||
assert.equal( | ||
reatomSet(new Set([1, 2, 3])).isDisjointFrom(ctx, new Set([3, 4, 5])), | ||
false, | ||
) | ||
}) | ||
|
||
test.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters