mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibJS: Add tests for new Math functions
This commit is contained in:
parent
7c9c3a10d3
commit
f30d4f22ef
Notes:
sideshowbarker
2024-07-19 00:29:47 +09:00
Author: https://github.com/Cleverking2003 Commit: https://github.com/SerenityOS/serenity/commit/f30d4f22ef4 Pull-request: https://github.com/SerenityOS/serenity/pull/4599 Reviewed-by: https://github.com/linusg
9 changed files with 97 additions and 0 deletions
28
Libraries/LibJS/Tests/builtins/Math/Math.atan2.js
Normal file
28
Libraries/LibJS/Tests/builtins/Math/Math.atan2.js
Normal 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);
|
||||
});
|
7
Libraries/LibJS/Tests/builtins/Math/Math.cosh.js
Normal file
7
Libraries/LibJS/Tests/builtins/Math/Math.cosh.js
Normal 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);
|
||||
});
|
9
Libraries/LibJS/Tests/builtins/Math/Math.fround.js
Normal file
9
Libraries/LibJS/Tests/builtins/Math/Math.fround.js
Normal 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);
|
||||
});
|
9
Libraries/LibJS/Tests/builtins/Math/Math.hypot.js
Normal file
9
Libraries/LibJS/Tests/builtins/Math/Math.hypot.js
Normal 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);
|
||||
});
|
9
Libraries/LibJS/Tests/builtins/Math/Math.log.js
Normal file
9
Libraries/LibJS/Tests/builtins/Math/Math.log.js
Normal 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);
|
||||
});
|
10
Libraries/LibJS/Tests/builtins/Math/Math.log10.js
Normal file
10
Libraries/LibJS/Tests/builtins/Math/Math.log10.js
Normal 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);
|
||||
});
|
11
Libraries/LibJS/Tests/builtins/Math/Math.log2.js
Normal file
11
Libraries/LibJS/Tests/builtins/Math/Math.log2.js
Normal 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);
|
||||
});
|
6
Libraries/LibJS/Tests/builtins/Math/Math.sinh.js
Normal file
6
Libraries/LibJS/Tests/builtins/Math/Math.sinh.js
Normal 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);
|
||||
});
|
8
Libraries/LibJS/Tests/builtins/Math/Math.tanh.js
Normal file
8
Libraries/LibJS/Tests/builtins/Math/Math.tanh.js
Normal 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);
|
||||
});
|
Loading…
Reference in a new issue