mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibJS: Add Math.sign()
This commit is contained in:
parent
bdfd1f1545
commit
b27834cf16
3 changed files with 60 additions and 0 deletions
42
Libraries/LibJS/Tests/Math.sign.js
Normal file
42
Libraries/LibJS/Tests/Math.sign.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
load("test-common.js");
|
||||
|
||||
function isPositiveZero(value) {
|
||||
return value === 0 && 1 / value === Infinity;
|
||||
}
|
||||
|
||||
function isNegativeZero(value) {
|
||||
return value === 0 && 1 / value === -Infinity;
|
||||
}
|
||||
|
||||
try {
|
||||
assert(Math.sign.length === 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([])));
|
||||
|
||||
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(-[])));
|
||||
|
||||
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")));
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue