|
| 1 | +# Copyright (c) 2025 OpenCyphal |
| 2 | +# This software is distributed under the terms of the MIT License. |
| 3 | +# Author: Huong Pham <[email protected]> |
| 4 | +from typing import List |
| 5 | + |
| 6 | + |
| 7 | +def _unittest_strictify_bool() -> None: |
| 8 | + # noinspection PyProtectedMember |
| 9 | + from pycyphal.application.register._value import _strictify |
| 10 | + |
| 11 | + s = [True, False] |
| 12 | + n = _strictify(s).bit |
| 13 | + assert n is not None |
| 14 | + v = n.value |
| 15 | + assert (s == v).all() # type: ignore[attr-defined] |
| 16 | + |
| 17 | + |
| 18 | +def _unittest_strictify_u64() -> None: |
| 19 | + # noinspection PyProtectedMember |
| 20 | + from pycyphal.application.register._value import _strictify |
| 21 | + |
| 22 | + s = [x * 1000000 for x in range(30)] |
| 23 | + n = _strictify(s).natural64 |
| 24 | + assert n is not None |
| 25 | + v = n.value |
| 26 | + assert (s == v).all() # type: ignore[attr-defined] |
| 27 | + |
| 28 | + |
| 29 | +def _unittest_strictify_u32() -> None: |
| 30 | + # noinspection PyProtectedMember |
| 31 | + from pycyphal.application.register._value import _strictify |
| 32 | + |
| 33 | + s = [x * 1000000 for x in range(60)] |
| 34 | + n = _strictify(s).natural32 |
| 35 | + assert n is not None |
| 36 | + v = n.value |
| 37 | + assert (s == v).all() # type: ignore[attr-defined] |
| 38 | + |
| 39 | + |
| 40 | +def _unittest_strictify_u16() -> None: |
| 41 | + # noinspection PyProtectedMember |
| 42 | + from pycyphal.application.register._value import _strictify |
| 43 | + |
| 44 | + s = [x * 100 for x in range(80)] |
| 45 | + n = _strictify(s).natural16 |
| 46 | + assert n is not None |
| 47 | + v = n.value |
| 48 | + assert (s == v).all() # type: ignore[attr-defined] |
| 49 | + |
| 50 | + |
| 51 | +def _unittest_strictify_i64() -> None: |
| 52 | + # noinspection PyProtectedMember |
| 53 | + from pycyphal.application.register._value import _strictify |
| 54 | + |
| 55 | + s = [-x * 1000000 for x in range(30)] |
| 56 | + n = _strictify(s).integer64 |
| 57 | + assert n is not None |
| 58 | + v = n.value |
| 59 | + assert (s == v).all() # type: ignore[attr-defined] |
| 60 | + |
| 61 | + |
| 62 | +def _unittest_strictify_i32() -> None: |
| 63 | + # noinspection PyProtectedMember |
| 64 | + from pycyphal.application.register._value import _strictify |
| 65 | + |
| 66 | + s = [-x * 1000000 for x in range(60)] |
| 67 | + n = _strictify(s).integer32 |
| 68 | + assert n is not None |
| 69 | + v = n.value |
| 70 | + assert (s == v).all() # type: ignore[attr-defined] |
| 71 | + |
| 72 | + |
| 73 | +def _unittest_strictify_i16() -> None: |
| 74 | + # noinspection PyProtectedMember |
| 75 | + from pycyphal.application.register._value import _strictify |
| 76 | + |
| 77 | + s = [-x * 100 for x in range(80)] |
| 78 | + n = _strictify(s).integer16 |
| 79 | + assert n is not None |
| 80 | + v = n.value |
| 81 | + assert (s == v).all() # type: ignore[attr-defined] |
0 commit comments