ray_test.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license
  3. * Copyright The Closure Library Authors.
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.module('goog.vec.RayTest');
  7. goog.setTestOnly();
  8. const Ray = goog.require('goog.vec.Ray');
  9. const testSuite = goog.require('goog.testing.testSuite');
  10. testSuite({
  11. testConstructor() {
  12. let new_ray = new Ray();
  13. assertElementsEquals([0, 0, 0], new_ray.origin);
  14. assertElementsEquals([0, 0, 0], new_ray.dir);
  15. new_ray = new Ray([1, 2, 3], [4, 5, 6]);
  16. assertElementsEquals([1, 2, 3], new_ray.origin);
  17. assertElementsEquals([4, 5, 6], new_ray.dir);
  18. },
  19. testSet() {
  20. const new_ray = new Ray();
  21. new_ray.set([2, 3, 4], [5, 6, 7]);
  22. assertElementsEquals([2, 3, 4], new_ray.origin);
  23. assertElementsEquals([5, 6, 7], new_ray.dir);
  24. },
  25. testSetOrigin() {
  26. const new_ray = new Ray();
  27. new_ray.setOrigin([1, 2, 3]);
  28. assertElementsEquals([1, 2, 3], new_ray.origin);
  29. assertElementsEquals([0, 0, 0], new_ray.dir);
  30. },
  31. testSetDir() {
  32. const new_ray = new Ray();
  33. new_ray.setDir([2, 3, 4]);
  34. assertElementsEquals([0, 0, 0], new_ray.origin);
  35. assertElementsEquals([2, 3, 4], new_ray.dir);
  36. },
  37. testEquals() {
  38. const r0 = new Ray([1, 2, 3], [4, 5, 6]);
  39. const r1 = new Ray([5, 2, 3], [4, 5, 6]);
  40. assertFalse(r0.equals(r1));
  41. assertFalse(r0.equals(null));
  42. assertTrue(r1.equals(r1));
  43. r1.setOrigin(r0.origin);
  44. assertTrue(r1.equals(r0));
  45. assertTrue(r0.equals(r1));
  46. },
  47. });