AnimationParser.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. topSuite("Ext.draw.sprite.AnimationParser", function() {
  2. var parser = Ext.draw.sprite.AnimationParser;
  3. describe("'data' (array) parser", function () {
  4. var empty = [],
  5. nonEmpty1 = [4, 8, 16, 32],
  6. nonEmpty2 = [-4, -8, -16, -32],
  7. smaller = [4, 8, 16],
  8. bigger = [2, 4, 8, 16, 32],
  9. punctured = [2, NaN, 8, null];
  10. it('should be able to transition from an empty to a non-empty array', function () {
  11. // Since no initial values were given, the compute will
  12. // return the target array for any delta value.
  13. var delta = 0.25;
  14. var result = parser.data.compute(empty, nonEmpty1, delta);
  15. expect(result).toEqual([4, 8, 16, 32]);
  16. });
  17. it('should be able to transition from a non-empty to an empty array', function () {
  18. var delta = 0.25;
  19. // Since we are transitioning to nothing, no intermediate
  20. // value can be calculated. So the intermediate values
  21. // are computed as if the target values were zeros.
  22. var result = parser.data.compute(nonEmpty1, empty, delta);
  23. expect(result).toEqual([3, 6, 12, 24]);
  24. });
  25. it('should be able to transition between two equal size arrays', function () {
  26. var delta = 0.25;
  27. // This is simply an interpolated value of the corresponding
  28. // elements in respective arrays.
  29. var result = parser.data.compute(nonEmpty1, nonEmpty2, delta);
  30. expect(result).toEqual([2, 4, 8, 16]);
  31. });
  32. it('should be able to transition from a smaller to a bigger arrray', function () {
  33. var delta = 0.5;
  34. // This will interpolate between respective elements,
  35. // until the smaller array is out of elements, but the
  36. // bigger one still has some. In that case the interpolation
  37. // will be made between the last element of the smaller
  38. // array and the extra elements of the bigger array.
  39. var result = parser.data.compute(smaller, bigger, delta);
  40. expect(result).toEqual([3, 6, 12, 16, 24]);
  41. });
  42. it('should be able to transition from a bigger to a smaller array', function () {
  43. var delta = 0.5;
  44. // Behaves just like the interpolation from smaller to bigger.
  45. var result = parser.data.compute(bigger, smaller, delta);
  46. expect(result).toEqual([3, 6, 12, 16, 24]);
  47. });
  48. it('should be able to transition from a punctured to a normal array', function () {
  49. var delta = 0.5;
  50. // When invalid numbers in the punctured array are encountered,
  51. // a value with the same index in the target array will be used
  52. // for the resulting array.
  53. var result = parser.data.compute(punctured, nonEmpty1, delta);
  54. expect(result).toEqual([3, 8, 12, 32]);
  55. });
  56. it('should be able to transition from a normal to a punctured array', function () {
  57. var delta = 0.5;
  58. // Just like with transitioning to an empty array, if the value
  59. // can't be found in the target array, a zero value will be used
  60. // instead.
  61. var result = parser.data.compute(nonEmpty1, punctured, delta);
  62. expect(result).toEqual([3, 4, 12, 16]);
  63. });
  64. });
  65. });