GeezerVison is showing github.com — assert: support `Float16Array` in loose deep equality checks · nodejs/node@7df9558
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/comparisons.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,6 +110,7 @@ const { | 110 | 110 | isBooleanObject, | 111 | 111 | isBigIntObject, | 112 | 112 | isSymbolObject, | | 113 | + isFloat16Array, | 113 | 114 | isFloat32Array, | 114 | 115 | isFloat64Array, | 115 | 116 | isKeyObject, | @@ -315,7 +316,8 @@ function objectComparisonStart(val1, val2, mode, memos) { | 315 | 316 | if (!isPartialArrayBufferView(val1, val2)) { | 316 | 317 | return false; | 317 | 318 | } | 318 | | - } else if (mode === kLoose && (isFloat32Array(val1) || isFloat64Array(val1))) { | | 319 | + } else if (mode === kLoose && | | 320 | + (isFloat32Array(val1) || isFloat64Array(val1) || isFloat16Array(val1))) { | 319 | 321 | if (!areSimilarFloatArrays(val1, val2)) { | 320 | 322 | return false; | 321 | 323 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-partial-deep-equal.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --js-float16array | | 2 | +// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above | 1 | 3 | 'use strict'; | 2 | 4 |
| 3 | 5 | const common = require('../common'); | 4 | 6 | const vm = require('node:vm'); | 5 | 7 | const assert = require('node:assert'); | 6 | 8 | const { describe, it } = require('node:test'); | 7 | 9 |
| | 10 | +// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line | | 11 | +const { Float16Array } = globalThis; | | 12 | + | 8 | 13 | const x = ['x']; | 9 | 14 |
| 10 | 15 | function createCircularObject() { | @@ -494,6 +499,11 @@ describe('Object Comparison Tests', () => { | 494 | 499 | actual: { dataView: new Uint8Array(3) }, | 495 | 500 | expected: { dataView: new DataView(new ArrayBuffer(3)) }, | 496 | 501 | }, | | 502 | + { | | 503 | + description: 'throws when comparing Float16Array([+0.0]) with Float16Array([-0.0])', | | 504 | + actual: new Float16Array([+0.0]), | | 505 | + expected: new Float16Array([-0.0]), | | 506 | + }, | 497 | 507 | { | 498 | 508 | description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])', | 499 | 509 | actual: new Float32Array([+0.0]), | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-typedarray-deepequal.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --js-float16array | | 2 | +// TODO(LiviaMedeiros): once `Float16Array` is unflagged in v8, remove the line above | 1 | 3 | 'use strict'; | 2 | 4 |
| 3 | 5 | require('../common'); | 4 | 6 | const assert = require('assert'); | 5 | 7 | const { test, suite } = require('node:test'); | 6 | 8 |
| | 9 | +// TODO(LiviaMedeiros): once linter recognizes `Float16Array`, remove next line | | 10 | +const { Float16Array } = globalThis; | | 11 | + | 7 | 12 | function makeBlock(f) { | 8 | 13 | const args = Array.prototype.slice.call(arguments, 1); | 9 | 14 | return function() { | @@ -20,6 +25,7 @@ suite('equalArrayPairs', () => { | 20 | 25 | [new Int8Array(1e5), new Int8Array(1e5)], | 21 | 26 | [new Int16Array(1e5), new Int16Array(1e5)], | 22 | 27 | [new Int32Array(1e5), new Int32Array(1e5)], | | 28 | + [new Float16Array(1e5), new Float16Array(1e5)], | 23 | 29 | [new Float32Array(1e5), new Float32Array(1e5)], | 24 | 30 | [new Float64Array(1e5), new Float64Array(1e5)], | 25 | 31 | [new Float32Array([+0.0]), new Float32Array([+0.0])], | @@ -41,6 +47,7 @@ suite('equalArrayPairs', () => { | 41 | 47 |
| 42 | 48 | suite('looseEqualArrayPairs', () => { | 43 | 49 | const looseEqualArrayPairs = [ | | 50 | + [new Float16Array([+0.0]), new Float16Array([-0.0])], | 44 | 51 | [new Float32Array([+0.0]), new Float32Array([-0.0])], | 45 | 52 | [new Float64Array([+0.0]), new Float64Array([-0.0])], | 46 | 53 | ]; | @@ -71,6 +78,8 @@ suite('notEqualArrayPairs', () => { | 71 | 78 | [new Int16Array([0]), new Uint16Array([256])], | 72 | 79 | [new Int16Array([-256]), new Uint16Array([0xff00])], // same bits | 73 | 80 | [new Int32Array([-256]), new Uint32Array([0xffffff00])], // ditto | | 81 | + [new Float16Array([0.1]), new Float16Array([0.0])], | | 82 | + [new Float16Array([0.1]), new Float16Array([0.1, 0.2])], | 74 | 83 | [new Float32Array([0.1]), new Float32Array([0.0])], | 75 | 84 | [new Float32Array([0.1]), new Float32Array([0.1, 0.2])], | 76 | 85 | [new Float64Array([0.1]), new Float64Array([0.0])], | |
|