Cylindrical.tests.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* global QUnit */
  2. import { Cylindrical } from '../../../../src/math/Cylindrical';
  3. import { Vector3 } from '../../../../src/math/Vector3';
  4. import { eps } from './Constants.tests';
  5. export default QUnit.module( 'Maths', () => {
  6. QUnit.module( 'Cylindrical', () => {
  7. // INSTANCING
  8. QUnit.test( "Instancing", ( assert ) => {
  9. var a = new Cylindrical();
  10. var radius = 10.0;
  11. var theta = Math.PI;
  12. var y = 5;
  13. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  14. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  15. assert.strictEqual( a.y, 0, "Default values: check y" );
  16. var a = new Cylindrical( radius, theta, y );
  17. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  18. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  19. assert.strictEqual( a.y, y, "Custom values: check y" );
  20. } );
  21. // PUBLIC STUFF
  22. QUnit.test( "set", ( assert ) => {
  23. var a = new Cylindrical();
  24. var radius = 10.0;
  25. var theta = Math.PI;
  26. var y = 5;
  27. a.set( radius, theta, y );
  28. assert.strictEqual( a.radius, radius, "Check radius" );
  29. assert.strictEqual( a.theta, theta, "Check theta" );
  30. assert.strictEqual( a.y, y, "Check y" );
  31. } );
  32. QUnit.test( "clone", ( assert ) => {
  33. var radius = 10.0;
  34. var theta = Math.PI;
  35. var y = 5;
  36. var a = new Cylindrical( radius, theta, y );
  37. var b = a.clone();
  38. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  39. a.radius = 1;
  40. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  41. } );
  42. QUnit.test( "copy", ( assert ) => {
  43. var radius = 10.0;
  44. var theta = Math.PI;
  45. var y = 5;
  46. var a = new Cylindrical( radius, theta, y );
  47. var b = new Cylindrical().copy( a );
  48. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  49. a.radius = 1;
  50. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  51. } );
  52. QUnit.test( "setFromVector3", ( assert ) => {
  53. var a = new Cylindrical( 1, 1, 1 );
  54. var b = new Vector3( 0, 0, 0 );
  55. var c = new Vector3( 3, - 1, - 3 );
  56. var expected = new Cylindrical( Math.sqrt( 9 + 9 ), Math.atan2( 3, - 3 ), - 1 );
  57. a.setFromVector3( b );
  58. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  59. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  60. assert.strictEqual( a.y, 0, "Zero-length vector: check y" );
  61. a.setFromVector3( c );
  62. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  63. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  64. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Normal vector: check y" );
  65. } );
  66. } );
  67. } );