InterleavedBuffer.tests.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. */
  4. /* global QUnit */
  5. import { InterleavedBuffer } from '../../../../src/core/InterleavedBuffer';
  6. import { DynamicDrawUsage } from '../../../../src/constants';
  7. export default QUnit.module( 'Core', () => {
  8. QUnit.module( 'InterleavedBuffer', () => {
  9. function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
  10. assert.ok( copiedInstance instanceof InterleavedBuffer, "the clone has the correct type" );
  11. for ( var i = 0; i < instance.array.length; i ++ ) {
  12. assert.ok( copiedInstance.array[ i ] === instance.array[ i ], "array was copied" );
  13. }
  14. assert.ok( copiedInstance.stride === instance.stride, "stride was copied" );
  15. assert.ok( copiedInstance.usage === DynamicDrawUsage, "usage was copied" );
  16. }
  17. // INSTANCING
  18. QUnit.todo( "Instancing", ( assert ) => {
  19. assert.ok( false, "everything's gonna be alright" );
  20. } );
  21. // PROPERTIES
  22. QUnit.test( "needsUpdate", ( assert ) => {
  23. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
  24. a.needsUpdate = true;
  25. assert.strictEqual( a.version, 1, "Check version increased" );
  26. } );
  27. // PUBLIC STUFF
  28. QUnit.todo( "isInterleavedBuffer", ( assert ) => {
  29. assert.ok( false, "everything's gonna be alright" );
  30. } );
  31. QUnit.test( "setUsage", ( assert ) => {
  32. var instance = new InterleavedBuffer();
  33. instance.setUsage( DynamicDrawUsage );
  34. assert.strictEqual( instance.usage, DynamicDrawUsage, "Usage was set" );
  35. } );
  36. QUnit.test( "copy", ( assert ) => {
  37. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  38. var instance = new InterleavedBuffer( array, 3 );
  39. instance.setUsage( DynamicDrawUsage );
  40. checkInstanceAgainstCopy( instance, instance.copy( instance ), assert );
  41. } );
  42. QUnit.test( "copyAt", ( assert ) => {
  43. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  44. var b = new InterleavedBuffer( new Float32Array( 9 ), 3 );
  45. var expected = new Float32Array( [ 4, 5, 6, 7, 8, 9, 1, 2, 3 ] );
  46. b.copyAt( 1, a, 2 );
  47. b.copyAt( 0, a, 1 );
  48. b.copyAt( 2, a, 0 );
  49. assert.deepEqual( b.array, expected, "Check the right values were replaced" );
  50. } );
  51. QUnit.test( "set", ( assert ) => {
  52. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  53. instance.set( [ 0, - 1 ] );
  54. assert.ok( instance.array[ 0 ] === 0 && instance.array[ 1 ] === - 1, "replace at first by default" );
  55. } );
  56. QUnit.test( "clone", ( assert ) => {
  57. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  58. var instance = new InterleavedBuffer( array, 3 );
  59. instance.setUsage( DynamicDrawUsage );
  60. checkInstanceAgainstCopy( instance, instance.clone(), assert );
  61. } );
  62. QUnit.test( "onUpload", ( assert ) => {
  63. var a = new InterleavedBuffer();
  64. var func = function () { };
  65. a.onUpload( func );
  66. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  67. } );
  68. // OTHERS
  69. QUnit.test( "count", ( assert ) => {
  70. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  71. assert.equal( instance.count, 2, "count is calculated via array length / stride" );
  72. } );
  73. } );
  74. } );
粤ICP备19079148号