mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibJS: Add tests for Math constants
This commit is contained in:
parent
03c3530d86
commit
402fd5a3a3
Notes:
sideshowbarker
2024-07-19 08:04:42 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/402fd5a3a39 Pull-request: https://github.com/SerenityOS/serenity/pull/1529 Reviewed-by: https://github.com/awesomekling
1 changed files with 28 additions and 0 deletions
28
Libraries/LibJS/Tests/Math-constants.js
Normal file
28
Libraries/LibJS/Tests/Math-constants.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
// FIXME: The parser seems to have issues with decimals,
|
||||
// so we multiply everything and compare with whole numbers.
|
||||
// I.e. 1233 < X * 1000 < 1235 instead of 1.233 < X < 1.235
|
||||
|
||||
try {
|
||||
// approx. 2.718
|
||||
assert(2717 < Math.E * 1000 < 2719);
|
||||
// approx. 0.693MATH
|
||||
assert(692 < Math.LN2 * 1000 < 694);
|
||||
// approx. 2.303
|
||||
assert(2302 < Math.LN10 * 1000 < 2304);
|
||||
// approx. 1.443
|
||||
assert(1442 < Math.LOG2E * 1000 < 1444);
|
||||
// approx. 0.434
|
||||
assert(433 < Math.LOG10E * 1000 < 435);
|
||||
// approx. 3.1415
|
||||
assert(31414 < Math.PI * 10000 < 31416);
|
||||
// approx. 0.707
|
||||
assert(706 < Math.SQRT1_2 * 1000 < 708);
|
||||
// approx. 1.414
|
||||
assert(1413 < Math.SQRT2 * 1000 < 1415);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Reference in a new issue