Skip to content

Commit

Permalink
LibJS: Add tests for new Math functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleverking2003 authored and awesomekling committed Dec 28, 2020
1 parent 7c9c3a1 commit f30d4f2
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.atan2.js
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.cosh.js
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.fround.js
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.hypot.js
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.log.js
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.log10.js
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.log2.js
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.sinh.js
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions Libraries/LibJS/Tests/builtins/Math/Math.tanh.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit f30d4f2

Please sign in to comment.