From d03fd7067c75ced98094fbfa3b813c78006922cb Mon Sep 17 00:00:00 2001 From: reczkok Date: Mon, 14 Oct 2024 17:22:31 +0200 Subject: [PATCH] infinity and nan tests --- packages/typed-binary/src/test/float.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/typed-binary/src/test/float.test.ts b/packages/typed-binary/src/test/float.test.ts index 94c0171..ad31168 100644 --- a/packages/typed-binary/src/test/float.test.ts +++ b/packages/typed-binary/src/test/float.test.ts @@ -67,4 +67,18 @@ describe('Float16Schema', () => { expect(decoded3).to.closeTo(value3, 0.000976); expect(decoded4).to.closeTo(value4, 16); }); + + it('should handle NaN and Infinity', () => { + const value1 = Number.POSITIVE_INFINITY; + const value2 = Number.NEGATIVE_INFINITY; + const value3 = Number.NaN; + + const decoded1 = encodeAndDecode(f16, value1); + const decoded2 = encodeAndDecode(f16, value2); + const decoded3 = encodeAndDecode(f16, value3); + + expect(decoded1).to.equal(value1); + expect(decoded2).to.equal(value2); + expect(decoded3).to.be.NaN; + }); });