예제 #1
0
def test_reference_counter(int_: AlternativeInt) -> None:
    int_refcount_before = sys.getrefcount(int_)

    result = int_.bit_length()

    int_refcount_after = sys.getrefcount(int_)
    assert int_refcount_after == int_refcount_before
예제 #2
0
def test_idempotence(ints_pair: AlternativeNativeIntsPair) -> None:
    alternative_int, native_int = ints_pair

    alternative, native = (AlternativeInt(alternative_int),
                           NativeInt(native_int))

    assert are_alternative_native_ints_equal(alternative, native)
예제 #3
0
def test_no_argument() -> None:
    alternative, native = AlternativeInt(), NativeInt()

    assert are_alternative_native_ints_equal(alternative, native)
예제 #4
0
def test_string_with_base(string_with_base: Tuple[str, int]) -> None:
    string, base = string_with_base

    alternative, native = AlternativeInt(string, base), NativeInt(string, base)

    assert are_alternative_native_ints_equal(alternative, native)
예제 #5
0
def test_decimal_string(string: str) -> None:
    alternative, native = AlternativeInt(string), NativeInt(string)

    assert are_alternative_native_ints_equal(alternative, native)
예제 #6
0
def test_basic(int_: AlternativeInt) -> None:
    result = int_.bit_length()

    assert isinstance(result, AlternativeInt)
예제 #7
0
def test_product(first: AlternativeInt, second: AlternativeInt) -> None:
    result = (first * second).bit_length()

    assert result <= first.bit_length() + second.bit_length()
예제 #8
0
def test_evenness(int_: AlternativeInt) -> None:
    result = int_.bit_length()

    assert result == (-int_).bit_length()
예제 #9
0
def test_positive_definiteness(int_: AlternativeInt) -> None:
    result = int_.bit_length()

    assert equivalence(not result, not int_)
예제 #10
0
def test_invalid_strings(string: str, base: int) -> None:
    with pytest.raises(ValueError):
        AlternativeInt(string, base)
예제 #11
0
def test_no_argument() -> None:
    result = AlternativeInt()

    assert isinstance(result, AlternativeInt)
    assert not result
예제 #12
0
def test_string_with_base(string_with_base: Tuple[str, int]) -> None:
    string, base = string_with_base

    result = AlternativeInt(string, base)

    assert isinstance(result, AlternativeInt)
예제 #13
0
def test_decimal_string(string: str) -> None:
    result = AlternativeInt(string)

    assert isinstance(result, AlternativeInt)