Skip to content

Commit

Permalink
Add tests for truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarice committed Dec 10, 2024
1 parent cae1259 commit 2a8f874
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/dialects/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ def test_IntegerType_normalized():
assert ui8.normalized_value(IntAttr(255)) == IntAttr(255)


def test_IntegerType_truncated():
si8 = IntegerType(8, Signedness.SIGNED)
ui8 = IntegerType(8, Signedness.UNSIGNED)

assert i8.normalized_value(IntAttr(-1), truncate_bits=True) == IntAttr(-1)
assert i8.normalized_value(IntAttr(1), truncate_bits=True) == IntAttr(1)
assert i8.normalized_value(IntAttr(255), truncate_bits=True) == IntAttr(-1)
assert i8.normalized_value(IntAttr(256), truncate_bits=True) == IntAttr(0)

assert si8.normalized_value(IntAttr(-1), truncate_bits=True) == IntAttr(-1)
assert si8.normalized_value(IntAttr(1), truncate_bits=True) == IntAttr(1)
assert si8.normalized_value(IntAttr(255), truncate_bits=True) == IntAttr(-1)
assert si8.normalized_value(IntAttr(256), truncate_bits=True) == IntAttr(0)

assert ui8.normalized_value(IntAttr(-1), truncate_bits=True) == IntAttr(255)
assert ui8.normalized_value(IntAttr(1), truncate_bits=True) == IntAttr(1)
assert ui8.normalized_value(IntAttr(255), truncate_bits=True) == IntAttr(255)
assert ui8.normalized_value(IntAttr(256), truncate_bits=True) == IntAttr(0)


def test_IntegerAttr_normalize():
"""
Test that the value within the accepted signless range is normalized to signed
Expand Down

0 comments on commit 2a8f874

Please sign in to comment.