[ramda] split tests to separate modules: 'median' - 'none' (#38615)

* move 'median' tests to separate file

* move 'memoizeWith' tests to separate file

* move 'merge' tests to separate file

* move 'mergeAll' tests to separate file

* move 'mergeDeepLeft' tests to separate file

* move 'mergeDeepRight' tests to separate file

* move 'mergeDeepWith' tests to separate file

* move 'mergeDeepWithKey' tests to separate file

* move 'mergeLeft' tests to separate file

* move 'mergeRight' tests to separate file

* move 'mergeWith' tests to separate file

* move 'mergeWithKey' tests to separate file

* move 'min' tests to separate file

* move 'minBy' tests to separate file

* move 'modulo' tests to separate file

* move 'move' tests to separate file

* move 'multiply' tests to separate file

* move 'nAry' tests to separate file

* move 'negate' tests to separate file

* move 'none' tests to separate file
This commit is contained in:
Mike Deverell 2019-10-03 18:26:02 -04:00 committed by Ryan Cavanaugh
parent 554555bf57
commit 25d2c9665b
22 changed files with 238 additions and 176 deletions

View File

@ -44,9 +44,6 @@ class F2 {
});
() => {
function takesNoArg() {
return true;
}
function takesOneArg(a: number) {
return [a];
}
@ -57,12 +54,6 @@ class F2 {
return [a, b, c];
}
R.nAry(0);
R.nAry(0, takesNoArg);
R.nAry(0, takesOneArg);
R.nAry(1, takesTwoArgs);
R.nAry(1, takesThreeArgs);
const u1: (a: any) => any = R.unary(takesOneArg);
const u2: (a: any) => any = R.unary(takesTwoArgs);
const u3: (a: any) => any = R.unary(takesThreeArgs);
@ -297,36 +288,6 @@ R.times(i, 5);
greetMsJaneJones("Hello"); // => 'Hello, Ms. Jane Jones!'
})();
(() => {
interface Vector {
x: number;
y: number;
}
let numberOfCalls = 0;
function vectorSum(a: Vector, b: Vector): Vector {
numberOfCalls += 1;
return {
x: a.x + b.x,
y: a.y + b.y
};
}
const memoVectorSum = R.memoizeWith((a, b) => JSON.stringify([a, b]), vectorSum);
memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 }
numberOfCalls; // => 1
memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 }
numberOfCalls; // => 1
memoVectorSum({ x: 1, y: 2 }, { x: 2, y: 3 }); // => { x: 3, y: 5 }
numberOfCalls; // => 2
// Note that argument order matters
memoVectorSum({ x: 2, y: 3 }, { x: 1, y: 2 }); // => { x: 3, y: 5 }
numberOfCalls; // => 3
})();
(() => {
const addOneOnce = R.once((x: number) => x + 1);
addOneOnce(10); // => 11
@ -516,29 +477,6 @@ interface Obj {
R.over(headLens, R.toUpper, ["a", "b", "c"]); // => ['A', 'b', 'c']
};
() => {
const sampleList = ['a', 'b', 'c', 'd', 'e', 'f'];
R.move<string>(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
R.move<string>(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation
const moveCurried1 = R.move(0, 2);
moveCurried1<string>(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
const moveCurried2 = R.move(0);
moveCurried2<string>(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
const moveCurried3 = R.move(0);
const moveCurried4 = moveCurried3(2);
moveCurried4<string>(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
};
() => {
R.none(R.isNaN, [1, 2, 3]); // => true
R.none(R.isNaN, [1, 2, 3, NaN]); // => false
R.none(R.isNaN)([1, 2, 3, NaN]); // => false
};
() => {
const list = ["foo", "bar", "baz", "quux"];
R.nth(1, list); // => 'bar'
@ -959,71 +897,6 @@ type Pair = KeyValuePair<string, number>;
R.set(xyLens, 4, testObj); // => {x: [{y: 4, z: 3}, {y: 4, z: 5}]}
R.over(xyLens, R.negate, testObj); // => {x: [{y: -2, z: 3}, {y: 4, z: 5}]}
};
() => {
R.merge({name: "fred", age: 10}, {age: 40});
// => { 'name': 'fred', 'age': 40 }
};
() => {
const a = R.mergeAll([{foo: 1}, {bar: 2}, {baz: 3}]); // => {foo:1,bar:2,baz:3}
const b = R.mergeAll([{foo: 1}, {foo: 2}, {bar: 2}]); // => {foo:2,bar:2}
};
() => {
const a = R.mergeDeepLeft({foo: {bar: 1}}, {foo: {bar: 2}}); // => {foo: {bar: 1}}
};
() => {
const a = R.mergeDeepRight({foo: {bar: 1}}, {foo: {bar: 2}}); // => {foo: bar: 2}}
};
() => {
const a = R.mergeDeepWith(
(a: number[], b: number[]) => a.concat(b),
{foo: {bar: [1, 2]}},
{foo: {bar: [3, 4]}},
); // => {foo: {bar: [1,2,3,4]}}
};
() => {
const a = R.mergeDeepWithKey(
(k: string, a: number[], b: number[]) => k === 'bar' ? a.concat(b) : a,
{foo: {bar: [1, 2], userIds: [42]}},
{foo: {bar: [3, 4], userIds: [34]}}
); // => { foo: { bar: [ 1, 2, 3, 4 ], userIds: [42] } }
};
() => {
R.mergeLeft({foo: {bar: 1}}, {foo: {bar: 2}}); // => {foo: {bar: 1}}
const curry1 = R.mergeLeft({foo: {bar: 1}});
curry1({foo: {bar: 2}}); // => {foo: {bar: 1}}
};
() => {
R.mergeRight({ name: 'fred', age: 10 }, { age: 40 });
// => { 'name': 'fred', 'age': 40 }
const withDefaults = R.mergeRight({x: 0, y: 0});
withDefaults({y: 2}); // => {x: 0, y: 2}
};
() => {
const a = R.mergeWith(R.concat,
{a: true, values: [10, 20]},
{b: true, values: [15, 35]});
// => { a: true, b: true, values: [10, 20, 15, 35] }
};
() => {
const concatValues = (k: string, l: string, r: string) => k === "values" ? R.concat(l, r) : r;
R.mergeWithKey(concatValues,
{a: true, thing: "foo", values: [10, 20]},
{b: true, thing: "bar", values: [15, 35]});
const merge = R.mergeWithKey(concatValues);
merge({a: true, thing: "foo", values: [10, 20]}, {b: true, thing: "bar", values: [15, 35]});
};
() => {
const orValue = 11;
const orValueStr = "str";
@ -1314,54 +1187,6 @@ type Pair = KeyValuePair<string, number>;
R.startsWith([1])([1, 2, 3]); // => true
};
() => {
const a: number = R.median([7, 2, 10, 9]); // => 8
const b: number = R.median([]); // => NaN
};
() => {
const x: number = R.min(9, 3); // => 3
const y: string = R.min("a", "z"); // => 'a'
};
() => {
function cmp(obj: { x: R.Ord }) {
return obj.x;
}
const a = {x: 1};
const b = {x: 2};
const c = {x: 3};
const d = {x: "a"};
const e = {x: "z"};
const f = {x: new Date(0)};
const g = {x: new Date(60 * 1000)};
R.minBy(cmp, a, b); // => {x: 1}
R.minBy(cmp)(a, b); // => {x: 1}
R.minBy(cmp)(a)(c);
R.minBy(cmp, d, e);
R.minBy(cmp)(f)(g);
};
() => {
R.modulo(17, 3); // => 2
// JS behavior:
R.modulo(-17, 3); // => -2
R.modulo(17, -3); // => 2
};
() => {
const double = R.multiply(2);
const triple = R.multiply(3);
double(3); // => 6
triple(4); // => 12
R.multiply(2, 5); // => 10
};
() => {
R.negate(42); // => -42
};
() => {
R.product([2, 4, 6, 8, 100, 1]); // => 38400
};

View File

@ -0,0 +1,6 @@
import * as R from 'ramda';
() => {
const a: number = R.median([7, 2, 10, 9]); // => 8
const b: number = R.median([]); // => NaN
};

View File

@ -0,0 +1,34 @@
import * as R from 'ramda';
(() => {
interface Vector {
x: number;
y: number;
}
let numberOfCalls = 0;
function vectorSum(a: Vector, b: Vector): Vector {
numberOfCalls += 1;
return {
x: a.x + b.x,
y: a.y + b.y,
};
}
const memoVectorSum = R.memoizeWith(
(a, b) => JSON.stringify([a, b]),
vectorSum,
);
memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 }
numberOfCalls; // => 1
memoVectorSum({ x: 1, y: 1 }, { x: 2, y: 2 }); // => { x: 3, y: 3 }
numberOfCalls; // => 1
memoVectorSum({ x: 1, y: 2 }, { x: 2, y: 3 }); // => { x: 3, y: 5 }
numberOfCalls; // => 2
// Note that argument order matters
memoVectorSum({ x: 2, y: 3 }, { x: 1, y: 2 }); // => { x: 3, y: 5 }
numberOfCalls; // => 3
})();

View File

@ -0,0 +1,6 @@
import * as R from 'ramda';
() => {
R.merge({ name: 'fred', age: 10 }, { age: 40 });
// => { 'name': 'fred', 'age': 40 }
};

View File

@ -0,0 +1,6 @@
import * as R from 'ramda';
() => {
const a = R.mergeAll([{ foo: 1 }, { bar: 2 }, { baz: 3 }]); // => {foo:1,bar:2,baz:3}
const b = R.mergeAll([{ foo: 1 }, { foo: 2 }, { bar: 2 }]); // => {foo:2,bar:2}
};

View File

@ -0,0 +1,5 @@
import * as R from 'ramda';
() => {
const a = R.mergeDeepLeft({ foo: { bar: 1 } }, { foo: { bar: 2 } }); // => {foo: {bar: 1}}
};

View File

@ -0,0 +1,5 @@
import * as R from 'ramda';
() => {
const a = R.mergeDeepRight({ foo: { bar: 1 } }, { foo: { bar: 2 } }); // => {foo: bar: 2}}
};

View File

@ -0,0 +1,9 @@
import * as R from 'ramda';
() => {
const a = R.mergeDeepWith(
(a: number[], b: number[]) => a.concat(b),
{ foo: { bar: [1, 2] } },
{ foo: { bar: [3, 4] } },
); // => {foo: {bar: [1,2,3,4]}}
};

View File

@ -0,0 +1,9 @@
import * as R from 'ramda';
() => {
const a = R.mergeDeepWithKey(
(k: string, a: number[], b: number[]) => (k === 'bar' ? a.concat(b) : a),
{ foo: { bar: [1, 2], userIds: [42] } },
{ foo: { bar: [3, 4], userIds: [34] } },
); // => { foo: { bar: [ 1, 2, 3, 4 ], userIds: [42] } }
};

View File

@ -0,0 +1,7 @@
import * as R from 'ramda';
() => {
R.mergeLeft({ foo: { bar: 1 } }, { foo: { bar: 2 } }); // => {foo: {bar: 1}}
const curry1 = R.mergeLeft({ foo: { bar: 1 } });
curry1({ foo: { bar: 2 } }); // => {foo: {bar: 1}}
};

View File

@ -0,0 +1,9 @@
import * as R from 'ramda';
() => {
R.mergeRight({ name: 'fred', age: 10 }, { age: 40 });
// => { 'name': 'fred', 'age': 40 }
const withDefaults = R.mergeRight({ x: 0, y: 0 });
withDefaults({ y: 2 }); // => {x: 0, y: 2}
};

View File

@ -0,0 +1,10 @@
import * as R from 'ramda';
() => {
const a = R.mergeWith(
R.concat,
{ a: true, values: [10, 20] },
{ b: true, values: [15, 35] },
);
// => { a: true, b: true, values: [10, 20, 15, 35] }
};

View File

@ -0,0 +1,16 @@
import * as R from 'ramda';
() => {
const concatValues = (k: string, l: string, r: string) =>
k === 'values' ? R.concat(l, r) : r;
R.mergeWithKey(
concatValues,
{ a: true, thing: 'foo', values: [10, 20] },
{ b: true, thing: 'bar', values: [15, 35] },
);
const merge = R.mergeWithKey(concatValues);
merge(
{ a: true, thing: 'foo', values: [10, 20] },
{ b: true, thing: 'bar', values: [15, 35] },
);
};

View File

@ -0,0 +1,6 @@
import * as R from 'ramda';
() => {
const x: number = R.min(9, 3); // => 3
const y: string = R.min('a', 'z'); // => 'a'
};

View File

@ -0,0 +1,20 @@
import * as R from 'ramda';
() => {
function cmp(obj: { x: R.Ord }) {
return obj.x;
}
const a = { x: 1 };
const b = { x: 2 };
const c = { x: 3 };
const d = { x: 'a' };
const e = { x: 'z' };
const f = { x: new Date(0) };
const g = { x: new Date(60 * 1000) };
R.minBy(cmp, a, b); // => {x: 1}
R.minBy(cmp)(a, b); // => {x: 1}
R.minBy(cmp)(a)(c);
R.minBy(cmp, d, e);
R.minBy(cmp)(f)(g);
};

View File

@ -0,0 +1,8 @@
import * as R from 'ramda';
() => {
R.modulo(17, 3); // => 2
// JS behavior:
R.modulo(-17, 3); // => -2
R.modulo(17, -3); // => 2
};

View File

@ -0,0 +1,18 @@
import * as R from 'ramda';
() => {
const sampleList = ['a', 'b', 'c', 'd', 'e', 'f'];
R.move<string>(0, 2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
R.move<string>(-1, 0, sampleList); // => ['f', 'a', 'b', 'c', 'd', 'e'] list rotation
const moveCurried1 = R.move(0, 2);
moveCurried1<string>(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
const moveCurried2 = R.move(0);
moveCurried2<string>(2, sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
const moveCurried3 = R.move(0);
const moveCurried4 = moveCurried3(2);
moveCurried4<string>(sampleList); // => ['b', 'c', 'a', 'd', 'e', 'f']
};

View File

@ -0,0 +1,9 @@
import * as R from 'ramda';
() => {
const double = R.multiply(2);
const triple = R.multiply(3);
double(3); // => 6
triple(4); // => 12
R.multiply(2, 5); // => 10
};

View File

@ -0,0 +1,22 @@
import * as R from 'ramda';
() => {
function takesNoArg() {
return true;
}
function takesOneArg(a: number) {
return [a];
}
function takesTwoArgs(a: number, b: number) {
return [a, b];
}
function takesThreeArgs(a: number, b: number, c: number) {
return [a, b, c];
}
R.nAry(0);
R.nAry(0, takesNoArg);
R.nAry(0, takesOneArg);
R.nAry(1, takesTwoArgs);
R.nAry(1, takesThreeArgs);
};

View File

@ -0,0 +1,5 @@
import * as R from 'ramda';
() => {
R.negate(42); // => -42
};

View File

@ -0,0 +1,7 @@
import * as R from 'ramda';
() => {
R.none(R.isNaN, [1, 2, 3]); // => true
R.none(R.isNaN, [1, 2, 3, NaN]); // => false
R.none(R.isNaN)([1, 2, 3, NaN]); // => false
};

View File

@ -132,6 +132,26 @@
"test/mathMod-tests.ts",
"test/max-tests.ts",
"test/maxBy-tests.ts",
"test/mean-tests.ts"
"test/mean-tests.ts",
"test/median-tests.ts",
"test/memoizeWith-tests.ts",
"test/merge-tests.ts",
"test/mergeAll-tests.ts",
"test/mergeDeepLeft-tests.ts",
"test/mergeDeepRight-tests.ts",
"test/mergeDeepWith-tests.ts",
"test/mergeDeepWithKey-tests.ts",
"test/mergeLeft-tests.ts",
"test/mergeRight-tests.ts",
"test/mergeWith-tests.ts",
"test/mergeWithKey-tests.ts",
"test/min-tests.ts",
"test/minBy-tests.ts",
"test/modulo-tests.ts",
"test/move-tests.ts",
"test/multiply-tests.ts",
"test/nAry-tests.ts",
"test/negate-tests.ts",
"test/none-tests.ts"
]
}