Skip to content

Instantly share code, notes, and snippets.

@stephank
Created April 12, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephank/2370677 to your computer and use it in GitHub Desktop.
Save stephank/2370677 to your computer and use it in GitHub Desktop.
TypedArray#set copy test
// console runnable test case adapted from:
// https://github.com/stephank/node-arrays/blob/master/test/typed-array-copy.js
function assertEq(desc, a, b) { console.log(desc + ": " + a + " == " + b + " ? " + (a == b)); }
a = new Uint16Array(8);
b = new Uint8Array(a.buffer, 0, 2);
b[0] = 0x05;
b[1] = 0x05;
assertEq('Uint16 value', a[0], 0x0505);
a.set(b);
assertEq('First Uint16 element', a[0], 0x0005);
assertEq('Second Uint16 element', a[1], 0x0005);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment