float32array_test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. // Use of this source code is governed by the Apache License, Version 2.0.
  3. goog.provide('goog.vec.Float32ArrayTest');
  4. goog.setTestOnly('goog.vec.Float32ArrayTest');
  5. goog.require('goog.testing.jsunit');
  6. goog.require('goog.vec.Float32Array');
  7. function testConstructorInitializesElementsToZero() {
  8. var f = new goog.vec.Float32Array(3);
  9. assertEquals(3, f.length);
  10. assertEquals(0, f[0]);
  11. assertEquals(0, f[1]);
  12. assertEquals(0, f[2]);
  13. assertEquals(4, f.BYTES_PER_ELEMENT);
  14. assertEquals(4, goog.vec.Float32Array.BYTES_PER_ELEMENT);
  15. }
  16. function testConstructorWithArrayAsArgument() {
  17. var f0 = new goog.vec.Float32Array([0, 0, 1, 0]);
  18. var f1 = new goog.vec.Float32Array(4);
  19. f1[0] = 0;
  20. f1[1] = 0;
  21. f1[2] = 1;
  22. f1[3] = 0;
  23. assertObjectEquals(f0, f1);
  24. }
  25. function testSet() {
  26. var f0 = new goog.vec.Float32Array(4);
  27. var f1 = new goog.vec.Float32Array(4);
  28. f0.set([1, 2, 3, 4]);
  29. f1[0] = 1;
  30. f1[1] = 2;
  31. f1[2] = 3;
  32. f1[3] = 4;
  33. assertObjectEquals(f0, f1);
  34. }
  35. function testSetWithOffset() {
  36. var f0 = new goog.vec.Float32Array(4);
  37. var f1 = new goog.vec.Float32Array(4);
  38. f0.set([5], 1);
  39. f1[0] = 0;
  40. f1[1] = 5;
  41. f1[2] = 0;
  42. f1[3] = 0;
  43. assertObjectEquals(f0, f1);
  44. }
  45. function testToString() {
  46. var f = new goog.vec.Float32Array([4, 3, 2, 1]);
  47. assertEquals('4,3,2,1', f.toString());
  48. }