|
| 1 | +// some asserts based on https://github.com/petamoriken/float16/blob/master/test/f16round.js |
| 2 | +import { createConversionChecker } from '../helpers/helpers'; |
| 3 | + |
| 4 | +const { MAX_VALUE, MIN_VALUE } = Number; |
| 5 | + |
| 6 | +QUnit.test('Math.f16round', assert => { |
| 7 | + const { f16round } = Math; |
| 8 | + assert.isFunction(f16round); |
| 9 | + assert.name(f16round, 'f16round'); |
| 10 | + assert.arity(f16round, 1); |
| 11 | + assert.looksNative(f16round); |
| 12 | + assert.nonEnumerable(Math, 'f16round'); |
| 13 | + assert.same(f16round(), NaN); |
| 14 | + assert.same(f16round(undefined), NaN); |
| 15 | + assert.same(f16round(NaN), NaN); |
| 16 | + assert.same(f16round(null), 0); |
| 17 | + assert.same(f16round(0), 0); |
| 18 | + assert.same(f16round(-0), -0); |
| 19 | + assert.same(f16round(MIN_VALUE), 0); |
| 20 | + assert.same(f16round(-MIN_VALUE), -0); |
| 21 | + assert.same(f16round(Infinity), Infinity); |
| 22 | + assert.same(f16round(-Infinity), -Infinity); |
| 23 | + assert.same(f16round(MAX_VALUE), Infinity); |
| 24 | + assert.same(f16round(-MAX_VALUE), -Infinity); |
| 25 | + |
| 26 | + const maxFloat16 = 65504; |
| 27 | + const minFloat16 = 2 ** -24; |
| 28 | + |
| 29 | + assert.same(f16round(maxFloat16), maxFloat16); |
| 30 | + assert.same(f16round(-maxFloat16), -maxFloat16); |
| 31 | + assert.same(f16round(minFloat16), minFloat16); |
| 32 | + assert.same(f16round(-minFloat16), -minFloat16); |
| 33 | + assert.same(f16round(minFloat16 / 2), 0); |
| 34 | + assert.same(f16round(-minFloat16 / 2), -0); |
| 35 | + assert.same(f16round(minFloat16 / 2 + 2 ** -25), minFloat16); |
| 36 | + assert.same(f16round(-minFloat16 / 2 - 2 ** -25), -minFloat16); |
| 37 | + |
| 38 | + assert.same(f16round(1.337), 1.3369140625); |
| 39 | + |
| 40 | + const checker = createConversionChecker(1.1); |
| 41 | + assert.same(f16round(checker), 1.099609375, 'object wrapper'); |
| 42 | + assert.same(checker.$valueOf, 1, 'valueOf calls'); |
| 43 | + assert.same(checker.$toString, 0, 'toString calls'); |
| 44 | +}); |
0 commit comments