|
| 1 | +import { floatType, intType } from '@h5web/shared/hdf5-utils'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +import { createIgnoreFillValue } from './utils'; |
| 5 | + |
| 6 | +describe('createIgnoreFillValue', () => { |
| 7 | + describe('with integers', () => { |
| 8 | + it('should ignore values greater or equal to positive fill value', () => { |
| 9 | + const ignoreValue = createIgnoreFillValue(10, intType()); |
| 10 | + expect(ignoreValue(9)).toBe(false); |
| 11 | + expect(ignoreValue(10)).toBe(true); |
| 12 | + expect(ignoreValue(11)).toBe(true); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should ignore values lower or equal to negative fill value', () => { |
| 16 | + const ignoreValue = createIgnoreFillValue(-10, intType()); |
| 17 | + expect(ignoreValue(-9)).toBe(false); |
| 18 | + expect(ignoreValue(-10)).toBe(true); |
| 19 | + expect(ignoreValue(-11)).toBe(true); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('with floats', () => { |
| 24 | + it('should ignore values greater than positive fill value', () => { |
| 25 | + const ignoreValue = createIgnoreFillValue(0.3, floatType(64)); |
| 26 | + expect(ignoreValue(0.2)).toBe(false); |
| 27 | + expect(ignoreValue(0.3005)).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should ignore values close-enough to positive fill value', () => { |
| 31 | + const ignoreValue = createIgnoreFillValue(0.3, floatType(64)); |
| 32 | + expect(ignoreValue(0.3 - 2 * Number.EPSILON)).toBe(false); |
| 33 | + expect(ignoreValue(0.3 - Number.EPSILON)).toBe(true); |
| 34 | + expect(ignoreValue(0.3)).toBe(true); |
| 35 | + expect(ignoreValue(0.3 + Number.EPSILON)).toBe(true); |
| 36 | + expect(ignoreValue(0.3 + 2 * Number.EPSILON)).toBe(true); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should ignore values lower than negative fill value', () => { |
| 40 | + const ignoreValue = createIgnoreFillValue(-0.3, floatType(64)); |
| 41 | + expect(ignoreValue(-0.2)).toBe(false); |
| 42 | + expect(ignoreValue(-0.3005)).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should ignore values close-enough to negative fill value', () => { |
| 46 | + const ignoreValue = createIgnoreFillValue(-0.3, floatType(64)); |
| 47 | + expect(ignoreValue(-0.3 + 2 * Number.EPSILON)).toBe(false); |
| 48 | + expect(ignoreValue(-0.3 + Number.EPSILON)).toBe(true); |
| 49 | + expect(ignoreValue(-0.3)).toBe(true); |
| 50 | + expect(ignoreValue(-0.3 - Number.EPSILON)).toBe(true); |
| 51 | + expect(ignoreValue(-0.3 - 2 * Number.EPSILON)).toBe(true); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments