From 39f1c24436ede8ab6c61d47263b7a705104c5767 Mon Sep 17 00:00:00 2001 From: Kato Hiroki Date: Wed, 23 Sep 2020 15:39:39 +0900 Subject: [PATCH 1/2] Add tests for internal bit (#33) --- tests/test__bit.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test__bit.py diff --git a/tests/test__bit.py b/tests/test__bit.py new file mode 100644 index 0000000..2422d33 --- /dev/null +++ b/tests/test__bit.py @@ -0,0 +1,54 @@ +import pytest + +from atcoder._bit import _ceil_pow2, _bsf + + +class TestInternalBit: + + @pytest.mark.parametrize(( + 'n', 'expected' + ), [ + (0, 0), + (1, 0), + (2, 1), + (3, 2), + (4, 2), + (5, 3), + (6, 3), + (7, 3), + (8, 3), + (9, 4), + ((1 << 30) - 1, 30), + (1 << 30, 30), + ((1 << 30) + 1, 31), + ((1 << 100) - 1, 100), + (1 << 100, 100), + ((1 << 100) + 1, 101), + ]) + def test_ceil_pow2(self, n, expected): + assert _ceil_pow2(n) == expected + + @pytest.mark.parametrize(( + 'n', 'expected' + ), [ + (1, 0), + (2, 1), + (3, 0), + (4, 2), + (5, 0), + (6, 1), + (7, 0), + (8, 3), + (9, 0), + ((1 << 30) - 1, 0), + (1 << 30, 30), + ((1 << 30) + 1, 0), + ((1 << 31) - 1, 0), + (1 << 31, 31), + ((1 << 31) + 1, 0), + ((1 << 100) - 1, 0), + (1 << 100, 100), + ((1 << 100) + 1, 0), + ]) + def test_bsf(self, n, expected): + assert _bsf(n) == expected From ce4b82754c0a97bad57db58d185343f2ddfb18f4 Mon Sep 17 00:00:00 2001 From: Kato Hiroki Date: Sun, 27 Sep 2020 10:20:34 +0900 Subject: [PATCH 2/2] Add type annotations --- tests/test__bit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test__bit.py b/tests/test__bit.py index 2422d33..7e50228 100644 --- a/tests/test__bit.py +++ b/tests/test__bit.py @@ -25,7 +25,7 @@ class TestInternalBit: (1 << 100, 100), ((1 << 100) + 1, 101), ]) - def test_ceil_pow2(self, n, expected): + def test_ceil_pow2(self, n: int, expected: int) -> None: assert _ceil_pow2(n) == expected @pytest.mark.parametrize(( @@ -50,5 +50,5 @@ def test_ceil_pow2(self, n, expected): (1 << 100, 100), ((1 << 100) + 1, 0), ]) - def test_bsf(self, n, expected): + def test_bsf(self, n: int, expected: int) -> None: assert _bsf(n) == expected