Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/tests/test_Math.js
/** | /** | ||||
* Tests for consistent and correct math results | * Tests for consistent and correct math results | ||||
*/ | */ | ||||
// +0 is different than -0, but standard equality won't test that | // +0 is different than -0, but standard equality won't test that | ||||
function isNegativeZero(z) { return z === 0 && 1/z === -Infinity; } | function isNegativeZero(z) { return z === 0 && 1/z === -Infinity; } | ||||
function isPositiveZero(z) { return z === 0 && 1/z === Infinity; } | function isPositiveZero(z) { return z === 0 && 1/z === Infinity; } | ||||
// rounding | // rounding | ||||
TS_ASSERT_EQUALS(0.1+0.2, 0.30000000000000004); | TS_ASSERT_EQUALS(0.1+0.2, 0.30000000000000004); | ||||
TS_ASSERT_EQUALS(0.1+0.7+0.3, 1.0999999999999999); | TS_ASSERT_EQUALS(0.1+0.7+0.3, 1.0999999999999999); | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
TS_ASSERT_EQUALS(Math.sqrt(Infinity), Infinity); | TS_ASSERT_EQUALS(Math.sqrt(Infinity), Infinity); | ||||
TS_ASSERT_EQUALS(Math.sqrt(1e-323), 3.1434555694052576e-162); | TS_ASSERT_EQUALS(Math.sqrt(1e-323), 3.1434555694052576e-162); | ||||
// square | // square | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(NaN), NaN); | TS_ASSERT_UNEVAL_EQUALS(Math.square(NaN), NaN); | ||||
TS_ASSERT(isPositiveZero(Math.square(0))); | TS_ASSERT(isPositiveZero(Math.square(0))); | ||||
TS_ASSERT(isPositiveZero(Math.square(-0))); | TS_ASSERT(isPositiveZero(Math.square(-0))); | ||||
TS_ASSERT_EQUALS(Math.square(Infinity), Infinity); | TS_ASSERT_EQUALS(Math.square(Infinity), Infinity); | ||||
TS_ASSERT_EQUALS(Math.square(1.772979291871526e-81),3.143455569405258e-162); | TS_ASSERT_EQUALS(Math.square(1.772979291871526e-81), 3.143455569405258e-162); | ||||
TS_ASSERT_EQUALS(Math.square(1e+155), Infinity); | TS_ASSERT_EQUALS(Math.square(1e+155), Infinity); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(1), 1); | TS_ASSERT_UNEVAL_EQUALS(Math.square(1), 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(20), 400); | TS_ASSERT_UNEVAL_EQUALS(Math.square(20), 400); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(300), 90000); | TS_ASSERT_UNEVAL_EQUALS(Math.square(300), 90000); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(4000), 16000000); | TS_ASSERT_UNEVAL_EQUALS(Math.square(4000), 16000000); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(50000), 2500000000); | TS_ASSERT_UNEVAL_EQUALS(Math.square(50000), 2500000000); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(-3), 9); | TS_ASSERT_UNEVAL_EQUALS(Math.square(-3), 9); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(-8), 64); | TS_ASSERT_UNEVAL_EQUALS(Math.square(-8), 64); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.square(0.123), 0.015129); | TS_ASSERT_UNEVAL_EQUALS(Math.square(0.123), 0.015129); | ||||
// euclid distance | // euclid distance | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(0, 0, 3, 4), 5); | TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(0, 0, 3, 4), 5); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(-4, -4, -5, -4), 1); | TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(-4, -4, -5, -4), 1); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(1e+140, 1e+140, 0, 0), 1.414213562373095e+140); | TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance2D(1e+140, 1e+140, 0, 0), 1.414213562373095e+140); | ||||
TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance3D(0, 0, 0, 20, 48, 165), 173); | TS_ASSERT_UNEVAL_EQUALS(Math.euclidDistance3D(0, 0, 0, 20, 48, 165), 173); |
Wildfire Games · Phabricator