Skip to content

Commit

Permalink
Add additional tests for implicit prefixes longer than 8 bit
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Mar 9, 2020
1 parent 638a65e commit db246cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pydsdl/_serializable/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,8 @@ def _unittest_variable_array() -> None:

outer = FixedLengthArrayType(small, 2)
assert outer.bit_length_set == {16, 24, 32, 40, 48}

assert VariableLengthArrayType(tu8, 100).length_field_type.bit_length == 8
assert VariableLengthArrayType(tu8, 10000).length_field_type.bit_length == 16
assert VariableLengthArrayType(tu8, 1000000).length_field_type.bit_length == 32
assert VariableLengthArrayType(tu8, 10000000000).length_field_type.bit_length == 64
14 changes: 14 additions & 0 deletions pydsdl/_serializable/_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,20 @@ def try_union_fields(field_types: typing.List[SerializableType]) -> UnionType:
SignedIntegerType(16, PrimitiveType.CastMode.SATURATED),
]).bit_length_set == {24}

assert try_union_fields(
[
UnsignedIntegerType(16, PrimitiveType.CastMode.TRUNCATED),
SignedIntegerType(16, PrimitiveType.CastMode.SATURATED),
] * 1000
).bit_length_set == {16 + 16}

assert try_union_fields(
[
UnsignedIntegerType(16, PrimitiveType.CastMode.TRUNCATED),
SignedIntegerType(16, PrimitiveType.CastMode.SATURATED),
] * 1000000
).bit_length_set == {32 + 16}

# The reference values for the following test are explained in the array tests above
tu8 = UnsignedIntegerType(8, cast_mode=PrimitiveType.CastMode.TRUNCATED)
small = VariableLengthArrayType(tu8, 2)
Expand Down

0 comments on commit db246cf

Please sign in to comment.