1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

Libraries: Move to Userland/Libraries/

This commit is contained in:
Andreas Kling 2021-01-12 12:17:30 +01:00
parent dc28c07fa5
commit 13d7c09125
1857 changed files with 266 additions and 274 deletions

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
expect(Math.E).toBeCloseTo(2.718281);
expect(Math.LN2).toBeCloseTo(0.693147);
expect(Math.LN10).toBeCloseTo(2.302585);
expect(Math.LOG2E).toBeCloseTo(1.442695);
expect(Math.LOG10E).toBeCloseTo(0.434294);
expect(Math.PI).toBeCloseTo(3.1415926);
expect(Math.SQRT1_2).toBeCloseTo(0.707106);
expect(Math.SQRT2).toBeCloseTo(1.414213);
});

View file

@ -0,0 +1,4 @@
test("basic functionality", () => {
expect(Math[Symbol.toStringTag]).toBe("Math");
expect(Math.toString()).toBe("[object Math]");
});

View file

@ -0,0 +1,14 @@
test("basic functionality", () => {
expect(Math.abs).toHaveLength(1);
expect(Math.abs("-1")).toBe(1);
expect(Math.abs(-2)).toBe(2);
expect(Math.abs(null)).toBe(0);
expect(Math.abs("")).toBe(0);
expect(Math.abs([])).toBe(0);
expect(Math.abs([2])).toBe(2);
expect(Math.abs([1, 2])).toBeNaN();
expect(Math.abs({})).toBeNaN();
expect(Math.abs("string")).toBeNaN();
expect(Math.abs()).toBeNaN();
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(Math.acosh).toHaveLength(1);
expect(Math.acosh(-1)).toBeNaN();
expect(Math.acosh(0)).toBeNaN();
expect(Math.acosh(0.5)).toBeNaN();
expect(Math.acosh(1)).toBeCloseTo(0);
expect(Math.acosh(2)).toBeCloseTo(1.316957);
});

View file

@ -0,0 +1,15 @@
test("basic functionality", () => {
expect(Math.asin).toHaveLength(1);
expect(Math.asin(0)).toBe(0);
expect(Math.asin(null)).toBe(0);
expect(Math.asin("")).toBe(0);
expect(Math.asin([])).toBe(0);
// FIXME(LibM): expect(Math.asin(1)).toBeCloseTo(1.5707963267948966);
// FIXME(LibM): expect(Math.asin(-1)).toBeCloseTo(-1.5707963267948966);
expect(Math.asin()).toBeNaN();
expect(Math.asin(undefined)).toBeNaN();
expect(Math.asin([1, 2, 3])).toBeNaN();
expect(Math.asin({})).toBeNaN();
expect(Math.asin("foo")).toBeNaN();
});

View file

@ -0,0 +1,6 @@
test("basic functionality", () => {
expect(Math.asinh).toHaveLength(1);
expect(Math.asinh(0)).toBeCloseTo(0);
expect(Math.asinh(1)).toBeCloseTo(0.881373);
});

View file

@ -0,0 +1,12 @@
test("basic functionality", () => {
expect(Math.atan).toHaveLength(1);
expect(Math.atan(0)).toBe(0);
expect(Math.atan(-0)).toBe(-0);
expect(Math.atan(NaN)).toBeNaN();
expect(Math.atan(-2)).toBeCloseTo(-1.1071487177940904);
expect(Math.atan(2)).toBeCloseTo(1.1071487177940904);
expect(Math.atan(Infinity)).toBeCloseTo(Math.PI / 2);
expect(Math.atan(-Infinity)).toBeCloseTo(-Math.PI / 2);
expect(Math.atan(0.5)).toBeCloseTo(0.4636476090008061);
});

View file

@ -0,0 +1,28 @@
test("basic functionality", () => {
expect(Math.atan2).toHaveLength(2);
expect(Math.atan2(90, 15)).toBeCloseTo(1.4056476493802699);
expect(Math.atan2(15, 90)).toBeCloseTo(0.16514867741462683);
expect(Math.atan2(+0, -0)).toBeCloseTo(Math.PI);
expect(Math.atan2(-0, -0)).toBeCloseTo(-Math.PI);
expect(Math.atan2(+0, +0)).toBe(0);
expect(Math.atan2(-0, +0)).toBe(-0);
expect(Math.atan2(+0, -1)).toBeCloseTo(Math.PI);
expect(Math.atan2(-0, -1)).toBeCloseTo(-Math.PI);
expect(Math.atan2(+0, 1)).toBe(0);
expect(Math.atan2(-0, 1)).toBe(-0);
expect(Math.atan2(-1, +0)).toBeCloseTo(-Math.PI / 2);
expect(Math.atan2(-1, -0)).toBeCloseTo(-Math.PI / 2);
expect(Math.atan2(1, +0)).toBeCloseTo(Math.PI / 2);
expect(Math.atan2(1, -0)).toBeCloseTo(Math.PI / 2);
expect(Math.atan2(1, -Infinity)).toBeCloseTo(Math.PI);
expect(Math.atan2(-1, -Infinity)).toBeCloseTo(-Math.PI);
expect(Math.atan2(1, +Infinity)).toBe(0);
expect(Math.atan2(-1, +Infinity)).toBe(-0);
expect(Math.atan2(+Infinity, 1)).toBeCloseTo(Math.PI / 2);
expect(Math.atan2(-Infinity, 1)).toBeCloseTo(-Math.PI / 2);
expect(Math.atan2(+Infinity, -Infinity)).toBeCloseTo((3 * Math.PI) / 4);
expect(Math.atan2(-Infinity, -Infinity)).toBeCloseTo((-3 * Math.PI) / 4);
expect(Math.atan2(+Infinity, +Infinity)).toBeCloseTo(Math.PI / 4);
expect(Math.atan2(-Infinity, +Infinity)).toBeCloseTo(-Math.PI / 4);
});

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
expect(Math.atanh).toHaveLength(1);
expect(Math.atanh(-2)).toBeNaN();
expect(Math.atanh(2)).toBeNaN();
expect(Math.atanh(-1)).toBe(-Infinity);
expect(Math.atanh(0)).toBe(0);
expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
expect(Math.atanh(1)).toBe(Infinity);
});

View file

@ -0,0 +1,12 @@
test("basic functionality", () => {
expect(Math.cbrt).toHaveLength(1);
expect(Math.cbrt(NaN)).toBeNaN();
expect(Math.cbrt(-1)).toBe(-1);
expect(Math.cbrt(-0)).toBe(-0);
expect(Math.cbrt(-Infinity)).toBe(-Infinity);
expect(Math.cbrt(1)).toBe(1);
expect(Math.cbrt(Infinity)).toBe(Infinity);
expect(Math.cbrt(null)).toBe(0);
expect(Math.cbrt(2)).toBeCloseTo(1.259921);
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
expect(Math.ceil).toHaveLength(1);
expect(Math.ceil(0.95)).toBe(1);
expect(Math.ceil(4)).toBe(4);
expect(Math.ceil(7.004)).toBe(8);
expect(Math.ceil(-0.95)).toBe(-0);
expect(Math.ceil(-4)).toBe(-4);
expect(Math.ceil(-7.004)).toBe(-7);
expect(Math.ceil()).toBeNaN();
expect(Math.ceil(NaN)).toBeNaN();
});

View file

@ -0,0 +1,44 @@
test("basic functionality", () => {
expect(Math.clz32).toHaveLength(1);
expect(Math.clz32(0)).toBe(32);
expect(Math.clz32(1)).toBe(31);
expect(Math.clz32(2)).toBe(30);
expect(Math.clz32(3)).toBe(30);
expect(Math.clz32(4)).toBe(29);
expect(Math.clz32(5)).toBe(29);
expect(Math.clz32(-1)).toBe(0);
expect(Math.clz32(-10)).toBe(0);
expect(Math.clz32(-100)).toBe(0);
expect(Math.clz32(-1000)).toBe(0);
expect(Math.clz32(-0.123)).toBe(32);
expect(Math.clz32(0.123)).toBe(32);
expect(Math.clz32(1.23)).toBe(31);
expect(Math.clz32(12)).toBe(28);
expect(Math.clz32(123)).toBe(25);
expect(Math.clz32(1234)).toBe(21);
expect(Math.clz32(12345)).toBe(18);
expect(Math.clz32(123456)).toBe(15);
expect(Math.clz32(1234567)).toBe(11);
expect(Math.clz32(12345678)).toBe(8);
expect(Math.clz32(123456789)).toBe(5);
expect(Math.clz32(999999999)).toBe(2);
expect(Math.clz32(9999999999)).toBe(1);
expect(Math.clz32(99999999999)).toBe(1);
expect(Math.clz32(999999999999)).toBe(0);
expect(Math.clz32(9999999999999)).toBe(1);
expect(Math.clz32(99999999999999)).toBe(3);
expect(Math.clz32(999999999999999)).toBe(0);
expect(Math.clz32()).toBe(32);
expect(Math.clz32(NaN)).toBe(32);
expect(Math.clz32(Infinity)).toBe(32);
expect(Math.clz32(-Infinity)).toBe(32);
expect(Math.clz32(false)).toBe(32);
expect(Math.clz32(true)).toBe(31);
expect(Math.clz32(null)).toBe(32);
expect(Math.clz32(undefined)).toBe(32);
expect(Math.clz32([])).toBe(32);
expect(Math.clz32({})).toBe(32);
expect(Math.clz32("foo")).toBe(32);
});

View file

@ -0,0 +1,14 @@
test("basic functionality", () => {
expect(Math.cos).toHaveLength(1);
expect(Math.cos(0)).toBe(1);
expect(Math.cos(null)).toBe(1);
expect(Math.cos("")).toBe(1);
expect(Math.cos([])).toBe(1);
expect(Math.cos(Math.PI)).toBe(-1);
expect(Math.cos()).toBeNaN();
expect(Math.cos(undefined)).toBeNaN();
expect(Math.cos([1, 2, 3])).toBeNaN();
expect(Math.cos({})).toBeNaN();
expect(Math.cos("foo")).toBeNaN();
});

View file

@ -0,0 +1,7 @@
test("basic functionality", () => {
expect(Math.cosh).toHaveLength(1);
expect(Math.cosh(0)).toBe(1);
expect(Math.cosh(1)).toBeCloseTo(1.5430806348152437);
expect(Math.cosh(-1)).toBeCloseTo(1.5430806348152437);
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
expect(Math.exp).toHaveLength(1);
expect(Math.exp(0)).toBe(1);
expect(Math.exp(-2)).toBeCloseTo(0.135335);
expect(Math.exp(-1)).toBeCloseTo(0.367879);
expect(Math.exp(1)).toBeCloseTo(2.718281);
expect(Math.exp(2)).toBeCloseTo(7.389056);
expect(Math.exp()).toBeNaN();
expect(Math.exp(undefined)).toBeNaN();
expect(Math.exp("foo")).toBeNaN();
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
expect(Math.expm1).toHaveLength(1);
expect(Math.expm1(0)).toBe(0);
expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
expect(Math.expm1(-1)).toBeCloseTo(-0.63212);
expect(Math.expm1(1)).toBeCloseTo(1.718281);
expect(Math.expm1(2)).toBeCloseTo(6.389056);
expect(Math.expm1()).toBeNaN();
expect(Math.expm1(undefined)).toBeNaN();
expect(Math.expm1("foo")).toBeNaN();
});

View file

@ -0,0 +1,13 @@
test("basic functionality", () => {
expect(Math.floor).toHaveLength(1);
expect(Math.floor(0.95)).toBe(0);
expect(Math.floor(4)).toBe(4);
expect(Math.floor(7.004)).toBe(7);
expect(Math.floor(-0.95)).toBe(-1);
expect(Math.floor(-4)).toBe(-4);
expect(Math.floor(-7.004)).toBe(-8);
expect(Math.floor()).toBeNaN();
expect(Math.floor(NaN)).toBeNaN();
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(Math.fround).toHaveLength(1);
expect(Math.fround(0)).toBe(0);
expect(Math.fround(1)).toBe(1);
expect(Math.fround(1.337)).toBeCloseTo(1.3370000123977661);
expect(Math.fround(1.5)).toBe(1.5);
expect(Math.fround(NaN)).toBe(NaN);
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(Math.hypot(3, 4)).toBe(5);
expect(Math.hypot(3, 4, 5)).toBeCloseTo(7.0710678118654755);
expect(Math.hypot()).toBe(0);
expect(Math.hypot(NaN)).toBe(NaN);
expect(Math.hypot(3, 4, "foo")).toBe(NaN);
expect(Math.hypot(3, 4, "5")).toBeCloseTo(7.0710678118654755);
expect(Math.hypot(-3)).toBe(3);
});

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(Math.log).toHaveLength(1);
expect(Math.log(-1)).toBe(NaN);
expect(Math.log(0)).toBe(-Infinity);
expect(Math.log(1)).toBe(0);
expect(Math.log(10)).toBeCloseTo(2.302585092994046);
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(Math.log10).toHaveLength(1);
expect(Math.log10(2)).toBeCloseTo(0.3010299956639812);
expect(Math.log10(1)).toBe(0);
expect(Math.log10(0)).toBe(-Infinity);
expect(Math.log10(-2)).toBe(NaN);
expect(Math.log10(100000)).toBe(5);
});

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(Math.log1p).toHaveLength(1);
expect(Math.log1p(-2)).toBeNaN();
expect(Math.log1p(-1)).toBe(-Infinity);
expect(Math.log1p(0)).toBe(0);
expect(Math.log1p(1)).toBeCloseTo(0.693147);
});

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
expect(Math.log2).toHaveLength(1);
expect(Math.log2(3)).toBeCloseTo(1.584962500721156);
expect(Math.log2(2)).toBe(1);
expect(Math.log2(1)).toBe(0);
expect(Math.log2(0)).toBe(-Infinity);
expect(Math.log2(-2)).toBe(NaN);
expect(Math.log2(1024)).toBe(10);
});

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
expect(Math.max).toHaveLength(2);
expect(Math.max()).toBe(-Infinity);
expect(Math.max(1)).toBe(1);
expect(Math.max(2, 1)).toBe(2);
expect(Math.max(1, 2, 3)).toBe(3);
expect(Math.max(NaN)).toBeNaN();
expect(Math.max("String", 1)).toBeNaN();
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(Math.min).toHaveLength(2);
expect(Math.min(1)).toBe(1);
expect(Math.min(2, 1)).toBe(1);
expect(Math.min(1, 2, 3)).toBe(1);
expect(Math.min(NaN)).toBeNaN();
expect(Math.min("String", 1)).toBeNaN();
});

View file

@ -0,0 +1,25 @@
test("basic functionality", () => {
expect(Math.pow).toHaveLength(2);
expect(Math.pow(2, 0)).toBe(1);
expect(Math.pow(2, 1)).toBe(2);
expect(Math.pow(2, 2)).toBe(4);
expect(Math.pow(2, 3)).toBe(8);
expect(Math.pow(2, -3)).toBe(0.125);
expect(Math.pow(3, 2)).toBe(9);
expect(Math.pow(0, 0)).toBe(1);
expect(Math.pow(2, Math.pow(3, 2))).toBe(512);
expect(Math.pow(Math.pow(2, 3), 2)).toBe(64);
expect(Math.pow("2", "3")).toBe(8);
expect(Math.pow("", [])).toBe(1);
expect(Math.pow([], null)).toBe(1);
expect(Math.pow(null, null)).toBe(1);
expect(Math.pow(undefined, null)).toBe(1);
expect(Math.pow(NaN, 2)).toBeNaN();
expect(Math.pow(2, NaN)).toBeNaN();
expect(Math.pow(undefined, 2)).toBeNaN();
expect(Math.pow(2, undefined)).toBeNaN();
expect(Math.pow(null, undefined)).toBeNaN();
expect(Math.pow(2, "foo")).toBeNaN();
expect(Math.pow("foo", 2)).toBeNaN();
});

View file

@ -0,0 +1,36 @@
function isPositiveZero(value) {
return value === 0 && 1 / value === Infinity;
}
function isNegativeZero(value) {
return value === 0 && 1 / value === -Infinity;
}
test("basic functionality", () => {
expect(Math.sign).toHaveLength(1);
expect(Math.sign(0.0001)).toBe(1);
expect(Math.sign(1)).toBe(1);
expect(Math.sign(42)).toBe(1);
expect(Math.sign(Infinity)).toBe(1);
expect(isPositiveZero(Math.sign(0))).toBeTrue();
expect(isPositiveZero(Math.sign(null))).toBeTrue();
expect(isPositiveZero(Math.sign(""))).toBeTrue();
expect(isPositiveZero(Math.sign([]))).toBeTrue();
expect(Math.sign(-0.0001)).toBe(-1);
expect(Math.sign(-1)).toBe(-1);
expect(Math.sign(-42)).toBe(-1);
expect(Math.sign(-Infinity)).toBe(-1);
expect(isNegativeZero(Math.sign(-0))).toBeTrue();
expect(isNegativeZero(Math.sign(-null))).toBeTrue();
expect(isNegativeZero(Math.sign(-""))).toBeTrue();
expect(isNegativeZero(Math.sign(-[]))).toBeTrue();
expect(Math.sign()).toBeNaN();
expect(Math.sign(undefined)).toBeNaN();
expect(Math.sign([1, 2, 3])).toBeNaN();
expect(Math.sign({})).toBeNaN();
expect(Math.sign(NaN)).toBeNaN();
expect(Math.sign("foo")).toBeNaN();
});

View file

@ -0,0 +1,15 @@
test("basic functionality", () => {
expect(Math.sin).toHaveLength(1);
expect(Math.sin(0)).toBe(0);
expect(Math.sin(null)).toBe(0);
expect(Math.sin("")).toBe(0);
expect(Math.sin([])).toBe(0);
expect(Math.sin((Math.PI * 3) / 2)).toBe(-1);
expect(Math.sin(Math.PI / 2)).toBe(1);
expect(Math.sin()).toBeNaN();
expect(Math.sin(undefined)).toBeNaN();
expect(Math.sin([1, 2, 3])).toBeNaN();
expect(Math.sin({})).toBeNaN();
expect(Math.sin("foo")).toBeNaN();
});

View file

@ -0,0 +1,6 @@
test("basic functionality", () => {
expect(Math.sinh).toHaveLength(1);
expect(Math.sinh(0)).toBe(0);
expect(Math.sinh(1)).toBeCloseTo(1.1752011936438014);
});

View file

@ -0,0 +1,4 @@
test("basic functionality", () => {
expect(Math.sqrt).toHaveLength(1);
expect(Math.sqrt(9)).toBe(3);
});

View file

@ -0,0 +1,14 @@
test("basic functionality", () => {
expect(Math.tan).toHaveLength(1);
expect(Math.tan(0)).toBe(0);
expect(Math.tan(null)).toBe(0);
expect(Math.tan("")).toBe(0);
expect(Math.tan([])).toBe(0);
expect(Math.ceil(Math.tan(Math.PI / 4))).toBe(1);
expect(Math.tan()).toBeNaN();
expect(Math.tan(undefined)).toBeNaN();
expect(Math.tan([1, 2, 3])).toBeNaN();
expect(Math.tan({})).toBeNaN();
expect(Math.tan("foo")).toBeNaN();
});

View file

@ -0,0 +1,8 @@
test("basic functionality", () => {
expect(Math.tanh).toHaveLength(1);
expect(Math.tanh(0)).toBe(0);
expect(Math.tanh(Infinity)).toBe(1);
expect(Math.tanh(-Infinity)).toBe(-1);
expect(Math.tanh(1)).toBeCloseTo(0.7615941559557649);
});

View file

@ -0,0 +1,12 @@
test("basic functionality", () => {
expect(Math.trunc).toHaveLength(1);
expect(Math.trunc(13.37)).toBe(13);
expect(Math.trunc(42.84)).toBe(42);
expect(Math.trunc(0.123)).toBe(0);
expect(Math.trunc(-0.123)).toBe(-0);
expect(Math.trunc(NaN)).toBeNaN();
expect(Math.trunc("foo")).toBeNaN();
expect(Math.trunc()).toBeNaN();
});