15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { defaultValue } from "../Source/Cesium.js";
import { defined } from "../Source/Cesium.js";
import { Math as CesiumMath } from "../Source/Cesium.js";
 
function createPackableSpecs(packable, instance, packedInstance, namePrefix) {
  namePrefix = defaultValue(namePrefix, "");
 
  it(namePrefix + " can pack", function () {
    var packedArray = [];
    var returnArray = packable.pack(instance, packedArray);
    expect(returnArray).toBe(packedArray);
    var packedLength = defined(packable.packedLength)
      ? packable.packedLength
      : instance.packedLength;
    expect(packedArray.length).toEqual(packedLength);
    expect(packedArray).toEqualEpsilon(packedInstance, CesiumMath.EPSILON15);
  });
 
  it(namePrefix + " can roundtrip", function () {
    var packedArray = [];
    packable.pack(instance, packedArray);
    var result = packable.unpack(packedArray);
    expect(instance).toEqual(result);
  });
 
  it(namePrefix + " can unpack", function () {
    var result = packable.unpack(packedInstance);
    expect(result).toEqual(instance);
  });
 
  it(namePrefix + " can pack with startingIndex", function () {
    var packedArray = [0];
    var expected = packedArray.concat(packedInstance);
    packable.pack(instance, packedArray, 1);
    expect(packedArray).toEqualEpsilon(expected, CesiumMath.EPSILON15);
  });
 
  it(namePrefix + " can unpack with startingIndex", function () {
    var packedArray = [0].concat(packedInstance);
    var result = packable.unpack(packedArray, 1);
    expect(instance).toEqual(result);
  });
 
  it(namePrefix + " pack throws with undefined value", function () {
    var array = [];
    expect(function () {
      packable.pack(undefined, array);
    }).toThrowDeveloperError();
  });
 
  it(namePrefix + " pack throws with undefined array", function () {
    expect(function () {
      packable.pack(instance, undefined);
    }).toThrowDeveloperError();
  });
 
  it(namePrefix + " unpack throws with undefined array", function () {
    expect(function () {
      packable.unpack(undefined);
    }).toThrowDeveloperError();
  });
 
  if (typeof packable.convertPackedArrayForInterpolation === "function") {
    it(namePrefix + " packs and unpacks for interpolation.", function () {
      var packedForInterpolation = [];
      packable.convertPackedArrayForInterpolation(
        packedInstance,
        0,
        0,
        packedForInterpolation
      );
      var value = packable.unpackInterpolationResult(
        packedForInterpolation,
        packedInstance,
        0,
        0
      );
      var result = packable.unpack(packedInstance);
      expect(value).toEqual(result);
    });
 
    it(
      namePrefix + " convertPackedArrayForInterpolation throws without array.",
      function () {
        expect(function () {
          packable.convertPackedArrayForInterpolation(undefined);
        }).toThrowDeveloperError();
      }
    );
 
    it(
      namePrefix + " unpackInterpolationResult throws without packed array.",
      function () {
        expect(function () {
          packable.unpackInterpolationResult(undefined, []);
        }).toThrowDeveloperError();
      }
    );
 
    it(
      namePrefix + " unpackInterpolationResult throws without source array.",
      function () {
        expect(function () {
          packable.unpackInterpolationResult([], undefined);
        }).toThrowDeveloperError();
      }
    );
  }
}
export default createPackableSpecs;