Face3.tests.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* global QUnit */
  2. import { Face3 } from '../../../../src/core/Face3';
  3. import { Color } from '../../../../src/math/Color';
  4. import { Vector3 } from '../../../../src/math/Vector3';
  5. export default QUnit.module( 'Core', () => {
  6. QUnit.module( 'Face3', () => {
  7. // INSTANCING
  8. QUnit.todo( "Instancing", ( assert ) => {
  9. assert.ok( false, "everything's gonna be alright" );
  10. } );
  11. // PUBLIC STUFF
  12. QUnit.test( "copy", ( assert ) => {
  13. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  14. var copiedInstance = new Face3().copy( instance );
  15. checkCopy( copiedInstance, assert );
  16. checkVertexAndColors( copiedInstance, assert );
  17. } );
  18. QUnit.test( "copy (more)", ( assert ) => {
  19. var instance = new Face3( 0, 1, 2,
  20. [ new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 1 ) ],
  21. [ new Color( 0.25, 0.5, 0.75 ), new Color( 1, 0, 0.4 ) ],
  22. 2 );
  23. var copiedInstance = new Face3().copy( instance );
  24. checkCopy( copiedInstance, assert );
  25. checkVertexAndColorArrays( copiedInstance, assert );
  26. } );
  27. QUnit.test( "clone", ( assert ) => {
  28. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  29. var copiedInstance = instance.clone();
  30. checkCopy( copiedInstance, assert );
  31. checkVertexAndColors( copiedInstance, assert );
  32. } );
  33. function checkCopy( copiedInstance, assert ) {
  34. assert.ok( copiedInstance instanceof Face3, "copy created the correct type" );
  35. assert.ok(
  36. copiedInstance.a === 0 &&
  37. copiedInstance.b === 1 &&
  38. copiedInstance.c === 2 &&
  39. copiedInstance.materialIndex === 2
  40. , "properties where copied" );
  41. }
  42. function checkVertexAndColors( copiedInstance, assert ) {
  43. assert.ok(
  44. copiedInstance.normal.x === 0 && copiedInstance.normal.y === 1 && copiedInstance.normal.z === 0 &&
  45. copiedInstance.color.r === 0.25 && copiedInstance.color.g === 0.5 && copiedInstance.color.b === 0.75
  46. , "properties where copied" );
  47. }
  48. function checkVertexAndColorArrays( copiedInstance, assert ) {
  49. assert.ok(
  50. copiedInstance.vertexNormals[ 0 ].x === 0 && copiedInstance.vertexNormals[ 0 ].y === 1 && copiedInstance.vertexNormals[ 0 ].z === 0 &&
  51. copiedInstance.vertexNormals[ 1 ].x === 1 && copiedInstance.vertexNormals[ 1 ].y === 0 && copiedInstance.vertexNormals[ 1 ].z === 1 &&
  52. copiedInstance.vertexColors[ 0 ].r === 0.25 && copiedInstance.vertexColors[ 0 ].g === 0.5 && copiedInstance.vertexColors[ 0 ].b === 0.75 &&
  53. copiedInstance.vertexColors[ 1 ].r === 1 && copiedInstance.vertexColors[ 1 ].g === 0 && copiedInstance.vertexColors[ 1 ].b === 0.4
  54. , "properties where copied" );
  55. }
  56. } );
  57. } );
粤ICP备19079148号