diff options
author | Egor Ananyin <ananinegor@gmail.com> | 2020-12-28 20:14:44 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 19:03:11 +0100 |
commit | f30d4f22ef4f3acfb4803b937177139b067fda3d (patch) | |
tree | 20c468ff30a85b4ae37fbd0028900923c45c24a2 /Libraries/LibJS/Tests/builtins | |
parent | 7c9c3a10d3d69c19df3a59cdc68a8e4c8b4de7a1 (diff) | |
download | serenity-f30d4f22ef4f3acfb4803b937177139b067fda3d.zip |
LibJS: Add tests for new Math functions
Diffstat (limited to 'Libraries/LibJS/Tests/builtins')
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.atan2.js | 28 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.cosh.js | 7 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.fround.js | 9 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.hypot.js | 9 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.log.js | 9 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.log10.js | 10 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.log2.js | 11 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.sinh.js | 6 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/builtins/Math/Math.tanh.js | 8 |
9 files changed, 97 insertions, 0 deletions
diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js b/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js new file mode 100644 index 0000000000..106fee51cc --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.atan2.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js b/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js new file mode 100644 index 0000000000..928b427028 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.cosh.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.fround.js b/Libraries/LibJS/Tests/builtins/Math/Math.fround.js new file mode 100644 index 0000000000..34b6c3f29f --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.fround.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js b/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js new file mode 100644 index 0000000000..ee4b1ea1b7 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.hypot.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log.js b/Libraries/LibJS/Tests/builtins/Math/Math.log.js new file mode 100644 index 0000000000..5be2a07a9d --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.log.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log10.js b/Libraries/LibJS/Tests/builtins/Math/Math.log10.js new file mode 100644 index 0000000000..d8ce28aca1 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.log10.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.log2.js b/Libraries/LibJS/Tests/builtins/Math/Math.log2.js new file mode 100644 index 0000000000..9b39d02c16 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.log2.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js b/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js new file mode 100644 index 0000000000..6ea3049c4c --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.sinh.js @@ -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); +}); diff --git a/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js b/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js new file mode 100644 index 0000000000..e24dae76c4 --- /dev/null +++ b/Libraries/LibJS/Tests/builtins/Math/Math.tanh.js @@ -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); +}); |