Marco Ricci
Convert Parametrizations enums to Parametrize namespace
Marco Ricci commited d1977d9 at 2025-02-01 23:25:35
test_derivepassphrase_sequin.py
# SPDX-FileCopyrightText: 2025 Marco Ricci <software@the13thletter.info>
#
# SPDX-License-Identifier: Zlib
"""Test sequin.Sequin."""
from __future__ import annotations
import collections
import contextlib
import functools
import math
import operator
import types
from typing import TYPE_CHECKING, NamedTuple
import hypothesis
import pytest
from hypothesis import strategies
from derivepassphrase import sequin
if TYPE_CHECKING:
from collections.abc import Sequence
def bits(num: int, /, byte_width: int | None = None) -> list[int]:
"""Return the list of bits of an integer, in big endian order.
Args:
num:
The number whose bits are to be returned.
byte_width:
Pad the returned list of bits to the given byte width if given,
else its natural byte width.
"""
if num < 0: # pragma: no cover
err_msg = 'Negative numbers are unsupported'
raise NotImplementedError(err_msg)
if byte_width is None:
byte_width = math.ceil(math.log2(num) / 8) if num else 1
seq: list[int] = []
while num:
seq.append(num % 2)
num >>= 1
seq.reverse()
missing_bit_count = 8 * byte_width - len(seq)
seq[:0] = [0] * missing_bit_count
return seq
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX