-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 progress: Import existing sources and tests from js-compare.
- Loading branch information
1 parent
49f0aba
commit d1a91bb
Showing
8 changed files
with
10,023 additions
and
26 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,19 +1,8 @@ | ||
# Usage | ||
|
||
> :warning: Depending on your environment, the code may require | ||
> `regeneratorRuntime` to be defined, for instance by importing | ||
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime). | ||
First, require the polyfill at the entry point of your application | ||
```js | ||
require( 'regenerator-runtime/runtime' ) ; | ||
// or | ||
import 'regenerator-runtime/runtime.js' ; | ||
``` | ||
|
||
Then, import the library where needed | ||
Import the library where needed | ||
```js | ||
const reversed = require( '@total-order/reversed' ) ; | ||
const {reversed} = require( '@total-order/reversed' ) ; | ||
// or | ||
import * as reversed from '@total-order/reversed' ; | ||
import {reversed} from '@total-order/reversed' ; | ||
``` |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
const answer = 42; | ||
export default answer; | ||
export {default as reversed} from './reversed.js'; |
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,9 @@ | ||
/** | ||
* Compile a new comparison function whose underlying total order is the | ||
* reverse of the input comparison function's underlying total order. | ||
* | ||
* @param {Function} compare The comparison function to reverse. | ||
* @return {Function} A function f such that compare(a,b) === f(b,a) for all a,b. | ||
*/ | ||
const reversed = (compare) => (a, b) => compare(b, a); | ||
export default reversed; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import test from 'ava'; | ||
import {increasing, decreasing} from '@total-order/primitive'; | ||
import {reversed} from '../../src/index.js'; | ||
|
||
const increasing2 = reversed(decreasing); | ||
const decreasing2 = reversed(increasing); | ||
|
||
const macro = (t, a, b) => { | ||
const i = increasing(a, b); | ||
const d = decreasing(a, b); | ||
const i2 = increasing2(a, b); | ||
const d2 = decreasing2(a, b); | ||
const ri = increasing(b, a); | ||
const rd = decreasing(b, a); | ||
const ri2 = increasing2(b, a); | ||
const rd2 = decreasing2(b, a); | ||
|
||
t.deepEqual(i, i2, `i i2 (${a}, ${b})`); | ||
t.deepEqual(-i, ri, `-i ri (${a}, ${b})`); | ||
t.deepEqual(-i, ri2, `-i ri2 (${a}, ${b})`); | ||
t.deepEqual(-i, d, `-i d (${a}, ${b})`); | ||
t.deepEqual(-i, d2, `-i d2 (${a}, ${b})`); | ||
t.deepEqual(i, rd, `i rd (${a}, ${b})`); | ||
t.deepEqual(i, rd2, `i rd2 (${a}, ${b})`); | ||
}; | ||
|
||
macro.title = (title, a, b) => title ?? `(${a}, ${b})`; | ||
|
||
const random = () => Math.random() - 0.5; | ||
|
||
for (let n = 0; n < 100; ++n) { | ||
test(macro, random(), random()); | ||
} |