Cylindrical.tests.js 2.8 KB

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