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
import { ImplicitAvailabilityBitstream } from "../../Source/Cesium.js";
 
describe("Scene/ImplicitAvailabilityBitstream", function () {
  it("throws on missing lengthBits", function () {
    expect(function () {
      return new ImplicitAvailabilityBitstream({});
    }).toThrowDeveloperError();
  });
 
  it("throws on mismatched bitLength and bitstream.length", function () {
    expect(function () {
      return new ImplicitAvailabilityBitstream({
        lengthBits: 17,
        bitstream: new Uint8Array([0xff, 0x02]),
      });
    }).toThrowRuntimeError();
  });
 
  it("reads bits from constant", function () {
    var length = 21;
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: length,
      constant: true,
    });
 
    for (var i = 0; i < length; i++) {
      expect(bitstream.getBit(i)).toEqual(true);
    }
  });
 
  it("reads bits from bitstream", function () {
    // This is the packed representation of
    // 0b0101 1111  1xxx xxxx
    // where the xs are unused bits.
    var bitstreamU8 = new Uint8Array([0xfa, 0x01]);
    var expected = [false, true, false, true, true, true, true, true, true];
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: expected.length,
      bitstream: bitstreamU8,
    });
 
    for (var i = 0; i < expected.length; i++) {
      expect(bitstream.getBit(i)).toEqual(expected[i]);
    }
  });
 
  it("throws on out of bounds", function () {
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: 10,
      bitstream: new Uint8Array([0xff, 0x02]),
    });
    expect(function () {
      bitstream.getBit(-1);
    }).toThrowDeveloperError();
 
    expect(function () {
      bitstream.getBit(10);
    }).toThrowDeveloperError();
  });
 
  it("stores availableCount", function () {
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: 10,
      availableCount: 3,
      bitstream: new Uint8Array([0x07, 0x00]),
    });
    expect(bitstream.availableCount).toEqual(3);
  });
 
  it("computes availableCount if enabled and availableCount is undefined", function () {
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: 10,
      bitstream: new Uint8Array([0xff, 0x02]),
      computeAvailableCountEnabled: true,
    });
    expect(bitstream.availableCount).toBe(9);
  });
 
  it("does not compute availableCount if disabled and availableCount is undefined", function () {
    var bitstream = new ImplicitAvailabilityBitstream({
      lengthBits: 10,
      bitstream: new Uint8Array([0xff, 0x02]),
    });
    expect(bitstream.availableCount).not.toBeDefined();
  });
});