InterleavedBuffer.tests.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* global QUnit */
  2. import { InterleavedBuffer } from '../../../../src/core/InterleavedBuffer.js';
  3. import { DynamicDrawUsage } from '../../../../src/constants.js';
  4. export default QUnit.module( 'Core', () => {
  5. QUnit.module( 'InterleavedBuffer', () => {
  6. function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
  7. assert.ok( copiedInstance instanceof InterleavedBuffer, 'the clone has the correct type' );
  8. for ( let i = 0; i < instance.array.length; i ++ ) {
  9. assert.ok( copiedInstance.array[ i ] === instance.array[ i ], 'array was copied' );
  10. }
  11. assert.ok( copiedInstance.stride === instance.stride, 'stride was copied' );
  12. assert.ok( copiedInstance.usage === DynamicDrawUsage, 'usage was copied' );
  13. }
  14. // INSTANCING
  15. QUnit.test( 'Instancing', ( assert ) => {
  16. const object = new InterleavedBuffer();
  17. assert.ok( object, 'Can instantiate an InterleavedBuffer.' );
  18. } );
  19. // PROPERTIES
  20. QUnit.todo( 'array', ( assert ) => {
  21. assert.ok( false, 'everything\'s gonna be alright' );
  22. } );
  23. QUnit.todo( 'stride', ( assert ) => {
  24. assert.ok( false, 'everything\'s gonna be alright' );
  25. } );
  26. QUnit.todo( 'count', ( assert ) => {
  27. assert.ok( false, 'everything\'s gonna be alright' );
  28. } );
  29. QUnit.todo( 'usage', ( assert ) => {
  30. assert.ok( false, 'everything\'s gonna be alright' );
  31. } );
  32. QUnit.todo( 'updateRange', ( assert ) => {
  33. assert.ok( false, 'everything\'s gonna be alright' );
  34. } );
  35. QUnit.todo( 'version', ( assert ) => {
  36. assert.ok( false, 'everything\'s gonna be alright' );
  37. } );
  38. QUnit.todo( 'uuid', ( assert ) => {
  39. assert.ok( false, 'everything\'s gonna be alright' );
  40. } );
  41. QUnit.todo( 'onUploadCallback', ( assert ) => {
  42. // onUploadCallback() {} declared but used as property, refactor req
  43. assert.ok( false, 'everything\'s gonna be alright' );
  44. } );
  45. QUnit.test( 'needsUpdate', ( assert ) => {
  46. const a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
  47. a.needsUpdate = true;
  48. assert.strictEqual( a.version, 1, 'Check version increased' );
  49. } );
  50. // PUBLIC
  51. QUnit.test( 'isInterleavedBuffer', ( assert ) => {
  52. const object = new InterleavedBuffer();
  53. assert.ok(
  54. object.isInterleavedBuffer,
  55. 'InterleavedBuffer.isInterleavedBuffer should be true'
  56. );
  57. } );
  58. QUnit.test( 'setUsage', ( assert ) => {
  59. const instance = new InterleavedBuffer();
  60. instance.setUsage( DynamicDrawUsage );
  61. assert.strictEqual( instance.usage, DynamicDrawUsage, 'Usage was set' );
  62. } );
  63. QUnit.test( 'copy', ( assert ) => {
  64. const array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  65. const instance = new InterleavedBuffer( array, 3 );
  66. instance.setUsage( DynamicDrawUsage );
  67. checkInstanceAgainstCopy( instance, instance.copy( instance ), assert );
  68. } );
  69. QUnit.test( 'copyAt', ( assert ) => {
  70. const a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  71. const b = new InterleavedBuffer( new Float32Array( 9 ), 3 );
  72. const expected = new Float32Array( [ 4, 5, 6, 7, 8, 9, 1, 2, 3 ] );
  73. b.copyAt( 1, a, 2 );
  74. b.copyAt( 0, a, 1 );
  75. b.copyAt( 2, a, 0 );
  76. assert.deepEqual( b.array, expected, 'Check the right values were replaced' );
  77. } );
  78. QUnit.test( 'set', ( assert ) => {
  79. const instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  80. instance.set( [ 0, - 1 ] );
  81. assert.ok( instance.array[ 0 ] === 0 && instance.array[ 1 ] === - 1, 'replace at first by default' );
  82. } );
  83. QUnit.todo( 'clone', ( assert ) => {
  84. assert.ok( false, 'everything\'s gonna be alright' );
  85. } );
  86. QUnit.test( 'onUpload', ( assert ) => {
  87. const a = new InterleavedBuffer();
  88. const func = function () { };
  89. a.onUpload( func );
  90. assert.strictEqual( a.onUploadCallback, func, 'Check callback was set properly' );
  91. } );
  92. QUnit.todo( 'toJSON', ( assert ) => {
  93. assert.ok( false, 'everything\'s gonna be alright' );
  94. } );
  95. // OTHERS
  96. QUnit.test( 'count', ( assert ) => {
  97. const instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  98. assert.equal( instance.count, 2, 'count is calculated via array length / stride' );
  99. } );
  100. } );
  101. } );
粤ICP备19079148号