Debian Codegraph @

mypyc/test/test_rarray.py

raw
1 """Unit tests for RArray types."""
2
3 from __future__ import annotations
4
5 import unittest
6
7 from mypyc.common import PLATFORM_SIZE
8 from mypyc.ir.rtypes import (
9 RArray,
10 bool_rprimitive,
11 compute_rtype_alignment,
12 compute_rtype_size,
13 int_rprimitive,
14 )
15
16
17 class TestRArray(unittest.TestCase):
18 def test_basics(self) -> None:
19 a = RArray(int_rprimitive, 10)
20 assert a.item_type == int_rprimitive
21 assert a.length == 10
22
23 def test_str_conversion(self) -> None:
24 a = RArray(int_rprimitive, 10)
25 assert str(a) == "int[10]"
26 assert repr(a) == "<RArray <RPrimitive builtins.int>[10]>"
27
28 def test_eq(self) -> None:
29 a = RArray(int_rprimitive, 10)
30 assert a == RArray(int_rprimitive, 10)
31 assert a != RArray(bool_rprimitive, 10)
32 assert a != RArray(int_rprimitive, 9)
33
34 def test_hash(self) -> None:
35 assert hash(RArray(int_rprimitive, 10)) == hash(RArray(int_rprimitive, 10))
36 assert hash(RArray(bool_rprimitive, 5)) == hash(RArray(bool_rprimitive, 5))
37
38 def test_alignment(self) -> None:
39 a = RArray(int_rprimitive, 10)
40 assert compute_rtype_alignment(a) == PLATFORM_SIZE
41 b = RArray(bool_rprimitive, 55)
42 assert compute_rtype_alignment(b) == 1
43
44 def test_size(self) -> None:
45 a = RArray(int_rprimitive, 9)
46 assert compute_rtype_size(a) == 9 * PLATFORM_SIZE
47 b = RArray(bool_rprimitive, 3)
48 assert compute_rtype_size(b) == 3