Marco Ricci
Update copyright notices to 2025, and license to zlib/libpng
Marco Ricci commited 8b97a77 at 2025-01-07 15:01:51
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 pytest
from derivepassphrase import sequin
def bitseq(string: str) -> list[int]:
"""Convert a 0/1-string into a list of bits."""
return [int(char, 2) for char in string]
class TestStaticFunctionality:
@pytest.mark.parametrize(
['sequence', 'base', 'expected'],
[
([1, 2, 3, 4, 5, 6], 10, 123456),
([1, 2, 3, 4, 5, 6], 100, 10203040506),
([0, 0, 1, 4, 9, 7], 10, 1497),
([1, 0, 0, 1, 0, 0, 0, 0], 2, 144),
([1, 7, 5, 5], 8, 0o1755),
],
)
def test_200_big_endian_number(
self, sequence: list[int], base: int, expected: int
) -> None:
assert (
sequin.Sequin._big_endian_number(sequence, base=base)
) == expected
@pytest.mark.parametrize(
['exc_type', 'exc_pattern', 'sequence', 'base'],
[
(ValueError, 'invalid base 3 digit:', [-1], 3),
(ValueError, 'invalid base:', [0], 1),
(TypeError, 'not an integer:', [0.0, 1.0, 0.0, 1.0], 2),
],
)
def test_300_big_endian_number_exceptions(
self,
exc_type: type[Exception],
exc_pattern: str,
sequence: list[int],
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX