LibJS: Add tests for new Math functions

This commit is contained in:
Egor Ananyin 2020-12-28 20:14:44 +03:00 committed by Andreas Kling
parent 7c9c3a10d3
commit f30d4f22ef
Notes: sideshowbarker 2024-07-19 00:29:47 +09:00
9 changed files with 97 additions and 0 deletions

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,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,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,9 @@
test("basic functionality", () => {
expect(Math.log).toHaveLength(1);
expect(Math.log(-1)).toBe(NaN);
expect(Math.log(0)).toBe(-Infinity);
// FIXME: not precise enough
//expect(Math.log(1)).toBe(0);
expect(Math.log(10)).toBeCloseTo(2.302585092994046);
});

View file

@ -0,0 +1,10 @@
test("basic functionality", () => {
expect(Math.log10).toHaveLength(1);
// FIXME: not precise enough
// 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,11 @@
test("basic functionality", () => {
expect(Math.log2).toHaveLength(1);
expect(Math.log2(3)).toBeCloseTo(1.584962500721156);
// FIXME: not precise enough
// 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,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,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);
});