mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibJS: Convert most builtin tests to new system
This commit is contained in:
parent
46581773c1
commit
3f97d75778
107 changed files with 2031 additions and 2243 deletions
|
@ -1,16 +1,10 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(isClose(Math.E, 2.718281));
|
||||
assert(isClose(Math.LN2, 0.693147));
|
||||
assert(isClose(Math.LN10, 2.302585));
|
||||
assert(isClose(Math.LOG2E, 1.442695));
|
||||
assert(isClose(Math.LOG10E, 0.434294));
|
||||
assert(isClose(Math.PI, 3.1415926));
|
||||
assert(isClose(Math.SQRT1_2, 0.707106));
|
||||
assert(isClose(Math.SQRT2, 1.414213));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.abs).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.abs('-1') === 1);
|
||||
assert(Math.abs(-2) === 2);
|
||||
assert(Math.abs(null) === 0);
|
||||
assert(Math.abs('') === 0);
|
||||
assert(Math.abs([]) === 0);
|
||||
assert(Math.abs([2]) === 2);
|
||||
assert(isNaN(Math.abs([1, 2])));
|
||||
assert(isNaN(Math.abs({})));
|
||||
assert(isNaN(Math.abs('string')));
|
||||
assert(isNaN(Math.abs()));
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.acosh).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(isNaN(Math.acosh(-1)));
|
||||
assert(isNaN(Math.acosh(0)));
|
||||
assert(isNaN(Math.acosh(0.5)));
|
||||
assert(isClose(Math.acosh(1), 0));
|
||||
// FIXME: assert(isClose(Math.acosh(2), 1.316957));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.acosh(-1)).toBeNaN();
|
||||
expect(Math.acosh(0)).toBeNaN();
|
||||
expect(Math.acosh(0.5)).toBeNaN();
|
||||
expect(Math.acosh(1)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.acosh(2)).toBeCloseTo(1.316957);
|
||||
});
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.asinh).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(isClose(Math.asinh(0), 0));
|
||||
|
||||
// FIXME: assert(isClose(Math.asinh(1), 0.881373));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.asinh(0)).toBeCloseTo(0);
|
||||
// FIXME: expect(Math.asinh(1)).toBeCloseTo(0.881373);
|
||||
});
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.atanh).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(isNaN(Math.atanh(-2)));
|
||||
assert(Math.atanh(-1) === -Infinity);
|
||||
// FIXME: assert(Math.atanh(0) === 0);
|
||||
assert(isClose(Math.atanh(0.5), 0.549306));
|
||||
// FIXME: assert(Math.atanh(1) === Infinity);
|
||||
assert(isNaN(Math.atanh(2)));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.atanh(-2)).toBeNaN();
|
||||
expect(Math.atanh(2)).toBeNaN();
|
||||
expect(Math.atanh(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.atanh(0)).toBe(0);
|
||||
expect(Math.atanh(0.5)).toBeCloseTo(0.549306);
|
||||
// FIXME: expect(Math.atanh(1)).toBe(Infinity);
|
||||
});
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.cbrt).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(isNaN(Math.cbrt(NaN)));
|
||||
// FIXME: assert(Math.cbrt(-1) === -1);
|
||||
assert(Math.cbrt(-0) === -0);
|
||||
// FIXME: assert(Math.cbrt(-Infinity) === -Infinity);
|
||||
// FIXME: assert(Math.cbrt(1) === 1);
|
||||
// FIXME: assert(Math.cbrt(Infinity) === Infinity);
|
||||
assert(Math.cbrt(null) === 0);
|
||||
// FIXME: assert(isClose(Math.cbrt(2), 1.259921));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.cbrt(NaN)).toBeNaN();
|
||||
// FIXME: expect(Math.cbrt(-1)).toBe(-1);
|
||||
expect(Math.cbrt(-0)).toBe(-0);
|
||||
// FIXME: expect(Math.cbrt(-Infinity)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.cbrt(1)).toBe(1);
|
||||
// FIXME: expect(Math.cbrt(Infinity)).toBe(Infinity);
|
||||
expect(Math.cbrt(null)).toBe(0);
|
||||
// FIXME: expect(Math.cbrt(2)).toBeCloseTo(1.259921));
|
||||
});
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.ceil).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.ceil(0.95) === 1);
|
||||
assert(Math.ceil(4) === 4);
|
||||
assert(Math.ceil(7.004) == 8);
|
||||
assert(Math.ceil(-0.95) === -0);
|
||||
assert(Math.ceil(-4) === -4);
|
||||
assert(Math.ceil(-7.004) === -7);
|
||||
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);
|
||||
|
||||
assert(isNaN(Math.ceil()));
|
||||
assert(isNaN(Math.ceil(NaN)));
|
||||
|
||||
assert(Math.ceil.length === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.ceil()).toBeNaN();
|
||||
expect(Math.ceil(NaN)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,50 +1,44 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.clz32).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.clz32.length === 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);
|
||||
|
||||
assert(Math.clz32(0) === 32);
|
||||
assert(Math.clz32(1) === 31);
|
||||
assert(Math.clz32(2) === 30);
|
||||
assert(Math.clz32(3) === 30);
|
||||
assert(Math.clz32(4) === 29);
|
||||
assert(Math.clz32(5) === 29);
|
||||
assert(Math.clz32(-1) === 0);
|
||||
assert(Math.clz32(-10) === 0);
|
||||
assert(Math.clz32(-100) === 0);
|
||||
assert(Math.clz32(-1000) === 0);
|
||||
assert(Math.clz32(-0.123) === 32);
|
||||
assert(Math.clz32(0.123) === 32);
|
||||
assert(Math.clz32(1.23) === 31);
|
||||
assert(Math.clz32(12) === 28);
|
||||
assert(Math.clz32(123) === 25);
|
||||
assert(Math.clz32(1234) === 21);
|
||||
assert(Math.clz32(12345) === 18);
|
||||
assert(Math.clz32(123456) === 15);
|
||||
assert(Math.clz32(1234567) === 11);
|
||||
assert(Math.clz32(12345678) === 8);
|
||||
assert(Math.clz32(123456789) === 5);
|
||||
assert(Math.clz32(999999999) === 2);
|
||||
assert(Math.clz32(9999999999) === 1);
|
||||
assert(Math.clz32(99999999999) === 1);
|
||||
assert(Math.clz32(999999999999) === 0);
|
||||
assert(Math.clz32(9999999999999) === 1);
|
||||
assert(Math.clz32(99999999999999) === 3);
|
||||
assert(Math.clz32(999999999999999) === 0);
|
||||
|
||||
assert(Math.clz32() === 32);
|
||||
assert(Math.clz32(NaN) === 32);
|
||||
assert(Math.clz32(Infinity) === 32);
|
||||
assert(Math.clz32(-Infinity) === 32);
|
||||
assert(Math.clz32(false) === 32);
|
||||
assert(Math.clz32(true) === 31);
|
||||
assert(Math.clz32(null) === 32);
|
||||
assert(Math.clz32(undefined) === 32);
|
||||
assert(Math.clz32([]) === 32);
|
||||
assert(Math.clz32({}) === 32);
|
||||
assert(Math.clz32("foo") === 32);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.cos).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.cos(0) === 1);
|
||||
assert(Math.cos(null) === 1);
|
||||
assert(Math.cos('') === 1);
|
||||
assert(Math.cos([]) === 1);
|
||||
assert(Math.cos(Math.PI) === -1);
|
||||
assert(isNaN(Math.cos()));
|
||||
assert(isNaN(Math.cos(undefined)));
|
||||
assert(isNaN(Math.cos([1, 2, 3])));
|
||||
assert(isNaN(Math.cos({})));
|
||||
assert(isNaN(Math.cos("foo")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.exp).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.exp.length === 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);
|
||||
|
||||
assert(Math.exp(0) === 1);
|
||||
assert(isClose(Math.exp(-2), 0.135335));
|
||||
assert(isClose(Math.exp(-1), 0.367879));
|
||||
assert(isClose(Math.exp(1), 2.718281));
|
||||
assert(isClose(Math.exp(2), 7.389056));
|
||||
|
||||
assert(isNaN(Math.exp()));
|
||||
assert(isNaN(Math.exp(undefined)));
|
||||
assert(isNaN(Math.exp("foo")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.exp()).toBeNaN();
|
||||
expect(Math.exp(undefined)).toBeNaN();
|
||||
expect(Math.exp("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.expm1).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.expm1.length === 1);
|
||||
expect(Math.expm1(0)).toBe(0);
|
||||
expect(Math.expm1(-2)).toBeCloseTo(-0.864664);
|
||||
expect(Math.expm1(-1)).toBeCloseTo(-0.632120);
|
||||
expect(Math.expm1(1)).toBeCloseTo(1.718281);
|
||||
expect(Math.expm1(2)).toBeCloseTo(6.389056);
|
||||
|
||||
assert(Math.expm1(0) === 0);
|
||||
assert(isClose(Math.expm1(-2), -0.864664));
|
||||
assert(isClose(Math.expm1(-1), -0.632120));
|
||||
assert(isClose(Math.expm1(1), 1.718281));
|
||||
assert(isClose(Math.expm1(2), 6.389056));
|
||||
|
||||
assert(isNaN(Math.expm1()));
|
||||
assert(isNaN(Math.expm1(undefined)));
|
||||
assert(isNaN(Math.expm1("foo")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.expm1()).toBeNaN();
|
||||
expect(Math.expm1(undefined)).toBeNaN();
|
||||
expect(Math.expm1("foo")).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.floor).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.floor(0.95) === 0);
|
||||
assert(Math.floor(4) === 4);
|
||||
assert(Math.floor(7.004) == 7);
|
||||
assert(Math.floor(-0.95) === -1);
|
||||
assert(Math.floor(-4) === -4);
|
||||
assert(Math.floor(-7.004) === -8);
|
||||
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);
|
||||
|
||||
assert(isNaN(Math.floor()));
|
||||
assert(isNaN(Math.floor(NaN)));
|
||||
|
||||
assert(Math.floor.length === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.floor()).toBeNaN();
|
||||
expect(Math.floor(NaN)).toBeNaN();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.log1p).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(isNaN(Math.log1p(-2)));
|
||||
assert(Math.log1p(-1) === -Infinity);
|
||||
// FIXME: assert(Math.log1p(0) === 0);
|
||||
// FIXME: assert(isClose(Math.log1p(1), 0.693147));
|
||||
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.log1p(-2)).toBeNaN();
|
||||
expect(Math.log1p(-1)).toBe(-Infinity);
|
||||
// FIXME: expect(Math.log1p(0)).toBe(0);
|
||||
// FIXME: expect(Math.log1p(1)).toBeCloseTo(0.693147);
|
||||
});
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.max).toHaveLength(2);
|
||||
|
||||
try {
|
||||
assert(Math.max.length === 2);
|
||||
assert(Math.max() === -Infinity);
|
||||
assert(Math.max(1) === 1);
|
||||
assert(Math.max(2, 1) === 2);
|
||||
assert(Math.max(1, 2, 3) === 3);
|
||||
assert(isNaN(Math.max(NaN)));
|
||||
assert(isNaN(Math.max("String", 1)));
|
||||
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
console.log("FAIL");
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
21
Libraries/LibJS/Tests/builtins/Math/Math.min.js
vendored
21
Libraries/LibJS/Tests/builtins/Math/Math.min.js
vendored
|
@ -1,14 +1,9 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.min).toHaveLength(2);
|
||||
|
||||
try {
|
||||
assert(Math.min.length === 2);
|
||||
assert(Math.min(1) === 1);
|
||||
assert(Math.min(2, 1) === 1);
|
||||
assert(Math.min(1, 2, 3) === 1);
|
||||
assert(isNaN(Math.min(NaN)));
|
||||
assert(isNaN(Math.min("String", 1)));
|
||||
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
console.log("FAIL");
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.pow).toHaveLength(2);
|
||||
|
||||
try {
|
||||
assert(Math.pow(2, 0) === 1);
|
||||
assert(Math.pow(2, 1) === 2);
|
||||
assert(Math.pow(2, 2) === 4);
|
||||
assert(Math.pow(2, 3) === 8);
|
||||
assert(Math.pow(2, -3) === 0.125);
|
||||
assert(Math.pow(3, 2) === 9);
|
||||
assert(Math.pow(0, 0) === 1);
|
||||
assert(Math.pow(2, Math.pow(3, 2)) === 512);
|
||||
assert(Math.pow(Math.pow(2, 3), 2) === 64);
|
||||
assert(Math.pow("2", "3") === 8);
|
||||
assert(Math.pow("", []) === 1);
|
||||
assert(Math.pow([], null) === 1);
|
||||
assert(Math.pow(null, null) === 1);
|
||||
assert(Math.pow(undefined, null) === 1);
|
||||
assert(isNaN(Math.pow(NaN, 2)));
|
||||
assert(isNaN(Math.pow(2, NaN)));
|
||||
assert(isNaN(Math.pow(undefined, 2)));
|
||||
assert(isNaN(Math.pow(2, undefined)));
|
||||
assert(isNaN(Math.pow(null, undefined)));
|
||||
assert(isNaN(Math.pow(2, "foo")));
|
||||
assert(isNaN(Math.pow("foo", 2)));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
load("test-common.js");
|
||||
|
||||
function isPositiveZero(value) {
|
||||
return value === 0 && 1 / value === Infinity;
|
||||
}
|
||||
|
@ -8,35 +6,33 @@ function isNegativeZero(value) {
|
|||
return value === 0 && 1 / value === -Infinity;
|
||||
}
|
||||
|
||||
try {
|
||||
assert(Math.sign.length === 1);
|
||||
test("basic functionality", () => {
|
||||
expect(Math.sign).toHaveLength(1);
|
||||
|
||||
assert(Math.sign(0.0001) === 1);
|
||||
assert(Math.sign(1) === 1);
|
||||
assert(Math.sign(42) === 1);
|
||||
assert(Math.sign(Infinity) === 1);
|
||||
assert(isPositiveZero(Math.sign(0)));
|
||||
assert(isPositiveZero(Math.sign(null)));
|
||||
assert(isPositiveZero(Math.sign('')));
|
||||
assert(isPositiveZero(Math.sign([])));
|
||||
expect(Math.sign.length).toBe(1);
|
||||
|
||||
assert(Math.sign(-0.0001) === -1);
|
||||
assert(Math.sign(-1) === -1);
|
||||
assert(Math.sign(-42) === -1);
|
||||
assert(Math.sign(-Infinity) === -1);
|
||||
assert(isNegativeZero(Math.sign(-0)));
|
||||
assert(isNegativeZero(Math.sign(-null)));
|
||||
assert(isNegativeZero(Math.sign(-'')));
|
||||
assert(isNegativeZero(Math.sign(-[])));
|
||||
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();
|
||||
|
||||
assert(isNaN(Math.sign()));
|
||||
assert(isNaN(Math.sign(undefined)));
|
||||
assert(isNaN(Math.sign([1, 2, 3])));
|
||||
assert(isNaN(Math.sign({})));
|
||||
assert(isNaN(Math.sign(NaN)));
|
||||
assert(isNaN(Math.sign("foo")));
|
||||
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();
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.sin).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.sin(0) === 0);
|
||||
assert(Math.sin(null) === 0);
|
||||
assert(Math.sin('') === 0);
|
||||
assert(Math.sin([]) === 0);
|
||||
assert(Math.sin(Math.PI * 3 / 2) === -1);
|
||||
assert(Math.sin(Math.PI / 2) === 1);
|
||||
assert(isNaN(Math.sin()));
|
||||
assert(isNaN(Math.sin(undefined)));
|
||||
assert(isNaN(Math.sin([1, 2, 3])));
|
||||
assert(isNaN(Math.sin({})));
|
||||
assert(isNaN(Math.sin("foo")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Math.sqrt(9) === 3);
|
||||
console.log("PASS");
|
||||
} catch {
|
||||
}
|
||||
test("basic functionality", () => {
|
||||
expect(Math.sqrt).toHaveLength(1);
|
||||
expect(Math.sqrt(9)).toBe(3);
|
||||
});
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
load("test-common.js");
|
||||
test("basic functionality", () => {
|
||||
expect(Math.tan).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.tan(0) === 0);
|
||||
assert(Math.tan(null) === 0);
|
||||
assert(Math.tan('') === 0);
|
||||
assert(Math.tan([]) === 0);
|
||||
assert(Math.ceil(Math.tan(Math.PI / 4)) === 1);
|
||||
assert(isNaN(Math.tan()));
|
||||
assert(isNaN(Math.tan(undefined)));
|
||||
assert(isNaN(Math.tan([1, 2, 3])));
|
||||
assert(isNaN(Math.tan({})));
|
||||
assert(isNaN(Math.tan("foo")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
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();
|
||||
});
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
load("test-common.js")
|
||||
test("basic functionality", () => {
|
||||
expect(Math.trunc).toHaveLength(1);
|
||||
|
||||
try {
|
||||
assert(Math.trunc(13.37) === 13);
|
||||
assert(Math.trunc(42.84) === 42);
|
||||
assert(Math.trunc(0.123) === 0);
|
||||
assert(Math.trunc(-0.123) === -0);
|
||||
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);
|
||||
|
||||
assert(isNaN(Math.trunc(NaN)));
|
||||
assert(isNaN(Math.trunc('foo')));
|
||||
assert(isNaN(Math.trunc()));
|
||||
|
||||
assert(Math.trunc.length === 1);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
expect(Math.trunc(NaN)).toBeNaN();
|
||||
expect(Math.trunc('foo')).toBeNaN();
|
||||
expect(Math.trunc()).toBeNaN();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue