ray_test.js 1.5 KB

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