float32array_test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license
  3. * Copyright The Closure Library Authors.
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.module('goog.vec.Float32ArrayTest');
  7. goog.setTestOnly();
  8. const VecFloat32Array = goog.require('goog.vec.Float32Array');
  9. const testSuite = goog.require('goog.testing.testSuite');
  10. testSuite({
  11. testConstructorInitializesElementsToZero() {
  12. const f = new VecFloat32Array(3);
  13. assertEquals(3, f.length);
  14. assertEquals(0, f[0]);
  15. assertEquals(0, f[1]);
  16. assertEquals(0, f[2]);
  17. assertEquals(4, f.BYTES_PER_ELEMENT);
  18. assertEquals(4, VecFloat32Array.BYTES_PER_ELEMENT);
  19. },
  20. testConstructorWithArrayAsArgument() {
  21. const f0 = new VecFloat32Array([0, 0, 1, 0]);
  22. const f1 = new VecFloat32Array(4);
  23. f1[0] = 0;
  24. f1[1] = 0;
  25. f1[2] = 1;
  26. f1[3] = 0;
  27. assertObjectEquals(f0, f1);
  28. },
  29. testSet() {
  30. const f0 = new VecFloat32Array(4);
  31. const f1 = new VecFloat32Array(4);
  32. f0.set([1, 2, 3, 4]);
  33. f1[0] = 1;
  34. f1[1] = 2;
  35. f1[2] = 3;
  36. f1[3] = 4;
  37. assertObjectEquals(f0, f1);
  38. },
  39. testSetWithOffset() {
  40. const f0 = new VecFloat32Array(4);
  41. const f1 = new VecFloat32Array(4);
  42. f0.set([5], 1);
  43. f1[0] = 0;
  44. f1[1] = 5;
  45. f1[2] = 0;
  46. f1[3] = 0;
  47. assertObjectEquals(f0, f1);
  48. },
  49. testToString() {
  50. const f = new VecFloat32Array([4, 3, 2, 1]);
  51. assertEquals('4,3,2,1', f.toString());
  52. },
  53. });