Atomics.or.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. test("invariants", () => {
  2. expect(Atomics.or).toHaveLength(3);
  3. });
  4. test("error cases", () => {
  5. expect(() => {
  6. Atomics.or("not an array", 0, 1);
  7. }).toThrow(TypeError);
  8. expect(() => {
  9. const bad_array_type = new Float32Array(4);
  10. Atomics.or(bad_array_type, 0, 1);
  11. }).toThrow(TypeError);
  12. expect(() => {
  13. const bad_array_type = new Uint8ClampedArray(4);
  14. Atomics.or(bad_array_type, 0, 1);
  15. }).toThrow(TypeError);
  16. expect(() => {
  17. const array = new Int32Array(4);
  18. Atomics.or(array, 100, 1);
  19. }).toThrow(RangeError);
  20. });
  21. test("basic functionality (non-BigInt)", () => {
  22. [Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array].forEach(ArrayType => {
  23. const array = new ArrayType(2);
  24. array[0] = 0b0000;
  25. array[1] = 0b0101;
  26. expect(Atomics.or(array, 0, 0b0000)).toBe(0b0000);
  27. expect(array).toEqual([0b0000, 0b0101]);
  28. expect(Atomics.or(array, 0, 0b1111)).toBe(0b0000);
  29. expect(array).toEqual([0b1111, 0b0101]);
  30. expect(Atomics.or(array, 1, 0b0101)).toBe(0b0101);
  31. expect(array).toEqual([0b1111, 0b0101]);
  32. expect(Atomics.or(array, 1, 0b1000)).toBe(0b0101);
  33. expect(array).toEqual([0b1111, 0b1101]);
  34. expect(Atomics.or(array, 1, 0b0010)).toBe(0b1101);
  35. expect(array).toEqual([0b1111, 0b1111]);
  36. });
  37. });
  38. test("basic functionality (BigInt)", () => {
  39. [BigInt64Array, BigUint64Array].forEach(ArrayType => {
  40. const array = new ArrayType(2);
  41. array[0] = 0b0000n;
  42. array[1] = 0b0101n;
  43. expect(Atomics.or(array, 0, 0b0000n)).toBe(0b0000n);
  44. expect(array).toEqual([0b0000n, 0b0101n]);
  45. expect(Atomics.or(array, 0, 0b1111n)).toBe(0b0000n);
  46. expect(array).toEqual([0b1111n, 0b0101n]);
  47. expect(Atomics.or(array, 1, 0b0101n)).toBe(0b0101n);
  48. expect(array).toEqual([0b1111n, 0b0101n]);
  49. expect(Atomics.or(array, 1, 0b1000n)).toBe(0b0101n);
  50. expect(array).toEqual([0b1111n, 0b1101n]);
  51. expect(Atomics.or(array, 1, 0b0010n)).toBe(0b1101n);
  52. expect(array).toEqual([0b1111n, 0b1111n]);
  53. });
  54. });