Prechádzať zdrojové kódy

LibJS: Simplify Math-constants.js test

By borrowing an "expect close" function from LibM/TestMath.cpp, we can
make this a lot simpler. Also the parser now understands decimals!
Linus Groh 5 rokov pred
rodič
commit
30ba2c7cec
1 zmenil súbory, kde vykonal 10 pridanie a 19 odobranie
  1. 10 19
      Libraries/LibJS/Tests/Math-constants.js

+ 10 - 19
Libraries/LibJS/Tests/Math-constants.js

@@ -1,24 +1,15 @@
-// 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
+// Borrowed from LibM/TestMath.cpp :^)
+function expectClose(a, b) { assert(Math.abs(a - b) < 0.000001); }
 
 
 try {
 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);
+    expectClose(Math.E, 2.718281);
+    expectClose(Math.LN2, 0.693147);
+    expectClose(Math.LN10, 2.302585);
+    expectClose(Math.LOG2E, 1.442695);
+    expectClose(Math.LOG10E, 0.434294);
+    expectClose(Math.PI, 3.1415926);
+    expectClose(Math.SQRT1_2, 0.707106);
+    expectClose(Math.SQRT2, 1.414213);
 
 
     console.log("PASS");
     console.log("PASS");
 } catch (e) {
 } catch (e) {