-
-
Notifications
You must be signed in to change notification settings - Fork 511
extended Bounded type #1544
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
Open
jessekelly881
wants to merge
19
commits into
gcanti:master
Choose a base branch
from
jessekelly881:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
extended Bounded type #1544
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
36c66a1
feat: extended Bounded type
jessekelly881 7cf0a65
chore: updated @since to 2.12.0
jessekelly881 2fa17e6
feat: added Predicate/ifElse, Predicate/ifElseW
jessekelly881 e9b5a3b
Merge branch 'gcanti:master' into master
jessekelly881 1fd7868
feat(Bounded): converted constructors to Option
jessekelly881 1d1a342
Merge branch 'master' of github.com:jessekelly881/fp-ts
jessekelly881 f5a8399
feat: removed yarn.lock
jessekelly881 d1a2718
refactor: removed Predicate/implies
jessekelly881 c2bb5a4
refactor: updated variable names
jessekelly881 999ce64
refactor: removed isEqual
jessekelly881 12610fd
refactor: removed ifElse, ifElseW
jessekelly881 846f657
refactor: removed test for Predicate/implies
jessekelly881 ab6a8bd
fix: fixed linting errors
jessekelly881 405edd1
feat(Bounded): added coerceBound
jessekelly881 5ec4632
chore: added @since to coerceBound
jessekelly881 dddad20
feat(Bounded): added reverse and isEmpty
jessekelly881 0ddcde0
refactor(Bounded): renamed isEmpty to isSingular
jessekelly881 e4a1adc
chore(Bounded): updated tests
jessekelly881 3173b7e
chore: ran prettier --write
jessekelly881 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,115 @@ | ||
| import { reverse, isSingular, coerceBound, fromRange, fromTuple, clamp, top, bottom, isWithin, toTuple, isValid } from '../src/Bounded' | ||
| import { BooleanAlgebra as b } from '../src/boolean' | ||
| import * as U from './util' | ||
| import * as n from '../src/number' | ||
| import { pipe } from '../src/function' | ||
| import fc from 'fast-check' | ||
| import * as Eq from '../src/Eq' | ||
|
|
||
| describe('Bounded', () => { | ||
|
|
||
| it('top', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (b, t) => | ||
| pipe({ ...n.Ord, bottom: b, top: t }, top, val => n.Eq.equals(t, val)) | ||
| )) | ||
| }) | ||
|
|
||
| it('bottom', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (b, t) => | ||
| pipe({ ...n.Ord, bottom: b, top: t }, bottom, val => n.Eq.equals(b, val)))) | ||
| }) | ||
|
|
||
| it('isValid', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (bottom, top) => | ||
| b.implies( | ||
| bottom <= top, | ||
| isValid({ ...n.Ord, bottom, top }) | ||
| ))) | ||
| }) | ||
|
|
||
| it('isSingular', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (bottom, top) => | ||
| b.implies(bottom === top, isSingular({ ...n.Ord, bottom, top }) && | ||
| b.implies(bottom !== top, !isSingular({ ...n.Ord, bottom, top }) | ||
| ))) | ||
| ) | ||
| }) | ||
|
|
||
| it('reverse', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (x, y) => { | ||
| const bound = { ...n.Ord, bottom: x, top: y } | ||
| const reverseBound = reverse(bound) | ||
|
|
||
| return top(bound) === bottom(reverseBound) && bottom(bound) === top(reverseBound) && | ||
| bound.compare(x, y) === reverseBound.compare(y, x) && | ||
| b.implies(isValid(bound), isValid(reverseBound)) | ||
|
|
||
| })) | ||
| }) | ||
|
|
||
| it('coerceBound', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (x, y) => { | ||
| const bound = coerceBound(n.Ord)(x)(y) | ||
|
|
||
| return isValid(bound) && | ||
| b.implies(x <= y, top(bound) === y && bottom(bound) === x) && | ||
| b.implies(y <= x, top(bound) === x && bottom(bound) === y) | ||
|
|
||
| })) | ||
| }) | ||
|
|
||
| it('toTuple', () => { | ||
| fc.assert(fc.property(fc.integer(), (bottom) => { | ||
| const top = bottom + 100 | ||
|
|
||
| return pipe( | ||
| { ...n.Ord, bottom, top }, | ||
| toTuple, | ||
| val => Eq.tuple(n.Eq, n.Eq).equals([bottom, top], val)) | ||
| })) | ||
| }) | ||
|
|
||
| it('isWithin', () => { | ||
| const inRange = isWithin({ ...n.Ord, bottom: 0, top: 10 }) | ||
|
|
||
| U.deepStrictEqual(inRange(2), true) | ||
| U.deepStrictEqual(inRange(10), true) | ||
| U.deepStrictEqual(inRange(0), true) | ||
| U.deepStrictEqual(inRange(20), false) | ||
| U.deepStrictEqual(inRange(-10), false) | ||
| }) | ||
|
|
||
| it('fromRange', () => { | ||
| const numRange = fromRange(n.Ord) | ||
|
|
||
| U.deepStrictEqual(numRange(0)(10)._tag, 'Some') | ||
| U.deepStrictEqual(numRange(0)(0)._tag, 'Some') | ||
| U.deepStrictEqual(numRange(-1)(0)._tag, 'Some') | ||
| U.deepStrictEqual(numRange(-1)(-2)._tag, 'None') | ||
| U.deepStrictEqual(numRange(1)(0)._tag, 'None') | ||
jessekelly881 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| it('fromTuple', () => { | ||
| const numRange = fromTuple(n.Ord) | ||
|
|
||
| U.deepStrictEqual(numRange([0, 10])._tag, 'Some') | ||
| U.deepStrictEqual(numRange([0,0])._tag, 'Some') | ||
| U.deepStrictEqual(numRange([-1, 0])._tag, 'Some') | ||
| U.deepStrictEqual(numRange([-1, -2])._tag, 'None') | ||
| U.deepStrictEqual(numRange([1, 0])._tag, 'None') | ||
jessekelly881 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| it('clamp', () => { | ||
| fc.assert(fc.property(fc.integer(), fc.integer(), (bottom, val) => { | ||
| const top = bottom + 100 | ||
| const bound = { ...n.Ord, bottom, top } | ||
|
|
||
| const clampedValue = clamp(bound)(val) | ||
|
|
||
| return b.implies(isWithin(bound)(val), clampedValue === val) && | ||
| b.implies(val < bottom, clampedValue === bottom) && | ||
| b.implies(val > top, clampedValue === top) | ||
| })) | ||
| }) | ||
|
|
||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.