-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
es.math.hypot.js
57 lines (54 loc) · 2.51 KB
/
es.math.hypot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { createConversionChecker } from '../helpers/helpers.js';
import hypot from 'core-js-pure/es/math/hypot';
QUnit.test('Math.hypot', assert => {
const { sqrt } = Math;
assert.isFunction(hypot);
assert.same(hypot(), 0);
assert.same(hypot(1), 1);
assert.same(hypot('', 0), 0);
assert.same(hypot(0, ''), 0);
assert.same(hypot(Infinity, 0), Infinity, 'Infinity, 0');
assert.same(hypot(-Infinity, 0), Infinity, '-Infinity, 0');
assert.same(hypot(0, Infinity), Infinity, '0, Infinity');
assert.same(hypot(0, -Infinity), Infinity, '0, -Infinity');
assert.same(hypot(Infinity, NaN), Infinity, 'Infinity, NaN');
assert.same(hypot(NaN, -Infinity), Infinity, 'NaN, -Infinity');
assert.same(hypot(NaN, 0), NaN, 'NaN, 0');
assert.same(hypot(0, NaN), NaN, '0, NaN');
assert.same(hypot(0, -0), 0);
assert.same(hypot(0, 0), 0);
assert.same(hypot(-0, -0), 0);
assert.same(hypot(-0, 0), 0);
assert.same(hypot(0, 1), 1);
assert.same(hypot(0, -1), 1);
assert.same(hypot(-0, 1), 1);
assert.same(hypot(-0, -1), 1);
assert.same(hypot(0), 0);
assert.same(hypot(1), 1);
assert.same(hypot(2), 2);
assert.same(hypot(0, 0, 1), 1);
assert.same(hypot(0, 1, 0), 1);
assert.same(hypot(1, 0, 0), 1);
assert.same(hypot(2, 3, 4), sqrt(2 * 2 + 3 * 3 + 4 * 4));
assert.same(hypot(2, 3, 4, 5), sqrt(2 * 2 + 3 * 3 + 4 * 4 + 5 * 5));
assert.closeTo(hypot(66, 66), 93.33809511662427, 1e-11);
assert.closeTo(hypot(0.1, 100), 100.0000499999875, 1e-11);
assert.same(hypot(1e+300, 1e+300), 1.4142135623730952e+300);
assert.same(Math.floor(hypot(1e-300, 1e-300) * 1e308), 141421356);
assert.same(hypot(1e+300, 1e+300, 2, 3), 1.4142135623730952e+300);
assert.same(hypot(-3, 4), 5);
assert.same(hypot(3, -4), 5);
const checker1 = createConversionChecker(2);
const checker2 = createConversionChecker(3);
const checker3 = createConversionChecker(4);
const checker4 = createConversionChecker(5);
assert.same(hypot(checker1, checker2, checker3, checker4), sqrt(2 * 2 + 3 * 3 + 4 * 4 + 5 * 5), 'object wrapper');
assert.same(checker1.$valueOf, 1, 'checker1 valueOf calls');
assert.same(checker1.$toString, 0, 'checker1 toString calls');
assert.same(checker2.$valueOf, 1, 'checker2 valueOf calls');
assert.same(checker2.$toString, 0, 'checker2 toString calls');
assert.same(checker3.$valueOf, 1, 'checker3 valueOf calls');
assert.same(checker3.$toString, 0, 'checker3 toString calls');
assert.same(checker4.$valueOf, 1, 'checker4 valueOf calls');
assert.same(checker4.$toString, 0, 'checker4 toString calls');
});