File: flex_types_test.dart

package info (click to toggle)
golang-github-google-flatbuffers 24.3.25-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 17,364 kB
  • sloc: cpp: 49,726; python: 6,901; cs: 5,566; java: 4,370; ansic: 2,512; php: 1,460; javascript: 1,053; xml: 1,016; sh: 870; makefile: 13
file content (184 lines) | stat: -rw-r--r-- 8,699 bytes parent folder | download | duplicates (10)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import 'package:flat_buffers/src/types.dart';
import 'package:test/test.dart';

void main() {
  test('is inline', () {
    expect(ValueTypeUtils.isInline(ValueType.Bool), isTrue);
    expect(ValueTypeUtils.isInline(ValueType.Int), isTrue);
    expect(ValueTypeUtils.isInline(ValueType.UInt), isTrue);
    expect(ValueTypeUtils.isInline(ValueType.Float), isTrue);
    expect(ValueTypeUtils.isInline(ValueType.Null), isTrue);
    expect(ValueTypeUtils.isInline(ValueType.String), isFalse);
  });
  test('is type vector element', () {
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Bool), isTrue);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Int), isTrue);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.UInt), isTrue);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Float), isTrue);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Key), isTrue);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.String), isTrue);

    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Null), isFalse);
    expect(ValueTypeUtils.isTypedVectorElement(ValueType.Blob), isFalse);
  });
  test('is typed vector', () {
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorInt), isTrue);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorUInt), isTrue);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorFloat), isTrue);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorBool), isTrue);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorKey), isTrue);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorString), isTrue);

    expect(ValueTypeUtils.isTypedVector(ValueType.Vector), isFalse);
    expect(ValueTypeUtils.isTypedVector(ValueType.Map), isFalse);
    expect(ValueTypeUtils.isTypedVector(ValueType.Bool), isFalse);
    expect(ValueTypeUtils.isTypedVector(ValueType.VectorInt2), isFalse);
  });
  test('is fixed typed vector', () {
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt2), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt3), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt4), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt2), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt3), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt4), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat2), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat3), isTrue);
    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat4), isTrue);

    expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt), isFalse);
  });
  test('to typed vector', () {
    expect(ValueTypeUtils.toTypedVector(ValueType.Int, 0),
        equals(ValueType.VectorInt));
    expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
        equals(ValueType.VectorUInt));
    expect(ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
        equals(ValueType.VectorBool));
    expect(ValueTypeUtils.toTypedVector(ValueType.Float, 0),
        equals(ValueType.VectorFloat));
    expect(ValueTypeUtils.toTypedVector(ValueType.Key, 0),
        equals(ValueType.VectorKey));
    expect(ValueTypeUtils.toTypedVector(ValueType.String, 0),
        equals(ValueType.VectorString));

    expect(ValueTypeUtils.toTypedVector(ValueType.Int, 2),
        equals(ValueType.VectorInt2));
    expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 2),
        equals(ValueType.VectorUInt2));
    expect(ValueTypeUtils.toTypedVector(ValueType.Float, 2),
        equals(ValueType.VectorFloat2));

    expect(ValueTypeUtils.toTypedVector(ValueType.Int, 3),
        equals(ValueType.VectorInt3));
    expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 3),
        equals(ValueType.VectorUInt3));
    expect(ValueTypeUtils.toTypedVector(ValueType.Float, 3),
        equals(ValueType.VectorFloat3));

    expect(ValueTypeUtils.toTypedVector(ValueType.Int, 4),
        equals(ValueType.VectorInt4));
    expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 4),
        equals(ValueType.VectorUInt4));
    expect(ValueTypeUtils.toTypedVector(ValueType.Float, 4),
        equals(ValueType.VectorFloat4));
  });
  test('typed vector element type', () {
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
        equals(ValueType.Int));
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
        equals(ValueType.UInt));
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
        equals(ValueType.Float));
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorString),
        equals(ValueType.String));
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorKey),
        equals(ValueType.Key));
    expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorBool),
        equals(ValueType.Bool));
  });
  test('fixed typed vector element type', () {
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
        equals(ValueType.Int));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3),
        equals(ValueType.Int));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4),
        equals(ValueType.Int));

    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2),
        equals(ValueType.UInt));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3),
        equals(ValueType.UInt));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4),
        equals(ValueType.UInt));

    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2),
        equals(ValueType.Float));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat3),
        equals(ValueType.Float));
    expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4),
        equals(ValueType.Float));
  });
  test('fixed typed vector element size', () {
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
        equals(2));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3),
        equals(3));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4),
        equals(4));

    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2),
        equals(2));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3),
        equals(3));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4),
        equals(4));

    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2),
        equals(2));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3),
        equals(3));
    expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
        equals(4));
  });
  test('packed type', () {
    expect(
        ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
    expect(
        ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
    expect(
        ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
    expect(
        ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));

    expect(
        ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
    expect(
        ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
    expect(
        ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
    expect(
        ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64), equals(7));
  });
  test('bit width', () {
    expect(BitWidthUtil.width(0), BitWidth.width8);
    expect(BitWidthUtil.width(-20), BitWidth.width8);
    expect(BitWidthUtil.width(127), BitWidth.width8);
    expect(BitWidthUtil.width(128), BitWidth.width16);
    expect(BitWidthUtil.width(128123), BitWidth.width32);
    expect(BitWidthUtil.width(12812324534), BitWidth.width64);
    expect(BitWidthUtil.width(-127), BitWidth.width8);
    expect(BitWidthUtil.width(-128), BitWidth.width16);
    expect(BitWidthUtil.width(-12812324534), BitWidth.width64);
    expect(BitWidthUtil.width(-0.1), BitWidth.width64);
    expect(BitWidthUtil.width(0.25), BitWidth.width32);
  });
  test('padding size', () {
    expect(BitWidthUtil.paddingSize(10, 8), 6);
    expect(BitWidthUtil.paddingSize(10, 4), 2);
    expect(BitWidthUtil.paddingSize(15, 4), 1);
    expect(BitWidthUtil.paddingSize(15, 2), 1);
    expect(BitWidthUtil.paddingSize(15, 1), 0);
    expect(BitWidthUtil.paddingSize(16, 8), 0);
    expect(BitWidthUtil.paddingSize(17, 8), 7);
  });
}