ray_test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.RayTest');
  4. goog.setTestOnly('goog.vec.RayTest');
  5. goog.require('goog.vec.Float32Array');
  6. goog.require('goog.vec.Ray');
  7. goog.require('goog.testing.jsunit');
  8. function testConstructor() {
  9. var new_ray = new goog.vec.Ray();
  10. assertElementsEquals([0, 0, 0], new_ray.origin);
  11. assertElementsEquals([0, 0, 0], new_ray.dir);
  12. new_ray = new goog.vec.Ray([1, 2, 3], [4, 5, 6]);
  13. assertElementsEquals([1, 2, 3], new_ray.origin);
  14. assertElementsEquals([4, 5, 6], new_ray.dir);
  15. }
  16. function testSet() {
  17. var new_ray = new goog.vec.Ray();
  18. new_ray.set([2, 3, 4], [5, 6, 7]);
  19. assertElementsEquals([2, 3, 4], new_ray.origin);
  20. assertElementsEquals([5, 6, 7], new_ray.dir);
  21. }
  22. function testSetOrigin() {
  23. var new_ray = new goog.vec.Ray();
  24. new_ray.setOrigin([1, 2, 3]);
  25. assertElementsEquals([1, 2, 3], new_ray.origin);
  26. assertElementsEquals([0, 0, 0], new_ray.dir);
  27. }
  28. function testSetDir() {
  29. var new_ray = new goog.vec.Ray();
  30. new_ray.setDir([2, 3, 4]);
  31. assertElementsEquals([0, 0, 0], new_ray.origin);
  32. assertElementsEquals([2, 3, 4], new_ray.dir);
  33. }
  34. function testEquals() {
  35. var r0 = new goog.vec.Ray([1, 2, 3], [4, 5, 6]);
  36. var r1 = new goog.vec.Ray([5, 2, 3], [4, 5, 6]);
  37. assertFalse(r0.equals(r1));
  38. assertFalse(r0.equals(null));
  39. assertTrue(r1.equals(r1));
  40. r1.setOrigin(r0.origin);
  41. assertTrue(r1.equals(r0));
  42. assertTrue(r0.equals(r1));
  43. }