Esempio n. 1
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)
Esempio n. 2
0
def test_basic(minuends_pair: AlternativeNativeIntsPair,
               subtrahends_pair: AlternativeNativeIntsPair) -> None:
    alternative_minuend, native_minuend = minuends_pair
    alternative_subtrahend, native_subtrahend = subtrahends_pair

    alternative_result = alternative_minuend - alternative_subtrahend
    native_result = native_minuend - native_subtrahend

    assert are_alternative_native_ints_equal(alternative_result, native_result)
Esempio n. 3
0
def test_basic(firsts_pair: AlternativeNativeIntsPair,
               seconds_pair: AlternativeNativeIntsPair) -> None:
    alternative_first, native_first = firsts_pair
    alternative_second, native_second = seconds_pair

    alternative_result = alternative_gcd(alternative_first, alternative_second)
    native_result = native_gcd(native_first, native_second)

    assert are_alternative_native_ints_equal(alternative_result, native_result)
Esempio n. 4
0
def test_basic(first_pair: AlternativeNativeIntsPair,
               second_pair: AlternativeNativeIntsPair) -> None:
    alternative_first, native_first = first_pair
    alternative_second, native_second = second_pair

    alternative_result = alternative_first ^ alternative_second
    native_result = native_first ^ native_second

    assert are_alternative_native_ints_equal(alternative_result, native_result)
Esempio n. 5
0
def test_basic(dividends_pair: AlternativeNativeIntsPair,
               divisors_pair: AlternativeNativeIntsPair) -> None:
    alternative_dividend, native_dividend = dividends_pair
    alternative_divisor, native_divisor = divisors_pair

    try:
        alternative_quotient, alternative_remainder = divmod(
            alternative_dividend, alternative_divisor)
    except ZeroDivisionError:
        with pytest.raises(ZeroDivisionError):
            divmod(native_dividend, native_divisor)
    else:
        native_quotient, native_remainder = divmod(native_dividend,
                                                   native_divisor)

        assert are_alternative_native_ints_equal(alternative_quotient,
                                                 native_quotient)
        assert are_alternative_native_ints_equal(alternative_remainder,
                                                 native_remainder)
Esempio n. 6
0
def test_basic(bases_pair: AlternativeNativeIntsPair,
               steps_pair: AlternativeNativeIntsPair) -> None:
    alternative_base, native_base = bases_pair
    alternative_step, native_step = steps_pair

    try:
        alternative_result = alternative_base >> alternative_step
    except ValueError:
        with pytest.raises(ValueError):
            native_base >> native_step
    else:
        native_result = native_base >> native_step

        assert are_alternative_native_ints_equal(alternative_result,
                                                 native_result)
Esempio n. 7
0
def test_basic(bases_pair: AlternativeNativeIntsPair,
               steps_pair: AlternativeNativeIntsPair) -> None:
    alternative_base, native_base = bases_pair
    alternative_step, native_step = steps_pair

    try:
        alternative_result = alternative_base << alternative_step
    except (MemoryError, OverflowError, ValueError) as error:
        with pytest.raises(type(error)):
            native_base << native_step
    else:
        native_result = native_base << native_step

        assert are_alternative_native_ints_equal(alternative_result,
                                                 native_result)
Esempio n. 8
0
def test_basic(dividends_pair: AlternativeNativeIntsPair,
               divisors_pair: AlternativeNativeIntsPair) -> None:
    alternative_dividend, native_dividend = dividends_pair
    alternative_divisor, native_divisor = divisors_pair

    try:
        alternative_result = alternative_dividend % alternative_divisor
    except ZeroDivisionError:
        with pytest.raises(ZeroDivisionError):
            native_dividend % native_divisor
    else:
        native_result = native_dividend % native_divisor

        assert are_alternative_native_ints_equal(alternative_result,
                                                 native_result)
Esempio n. 9
0
def test_basic(exponents_pair: AlternativeNativeIntsPair,
               bases_pair: AlternativeNativeFractionsPair) -> None:
    alternative_base, native_base = exponents_pair
    alternative_exponent, native_exponent = bases_pair

    try:
        alternative_result = alternative_base**alternative_exponent
    except ZeroDivisionError:
        with pytest.raises(ZeroDivisionError):
            native_base**native_exponent
    else:
        native_result = native_base**native_exponent

        assert (alternative_result == native_result if isinstance(
            alternative_result, type(native_result)) else
                (are_alternative_native_ints_equal(
                    alternative_result, native_result) if isinstance(
                        alternative_result, AlternativeInt) else
                 are_alternative_native_fractions_equal(
                     alternative_result, native_result)))
Esempio n. 10
0
def test_basic(
    bases_pair: AlternativeNativeIntsPair,
    exponents_pair_with_moduli_pair: Tuple[AlternativeNativeIntsPair,
                                           Union[Tuple[None, None],
                                                 AlternativeNativeIntsPair]]
) -> None:
    alternative_base, native_base = bases_pair
    exponents_pair, moduli_pair = exponents_pair_with_moduli_pair
    alternative_exponent, native_exponent = exponents_pair
    alternative_modulus, native_modulus = moduli_pair

    try:
        alternative_result = pow(alternative_base, alternative_exponent,
                                 alternative_modulus)
    except (ValueError, ZeroDivisionError) as error:
        with pytest.raises(type(error)):
            pow(native_base, native_exponent, native_modulus)
    else:
        native_result = pow(native_base, native_exponent, native_modulus)

        assert (alternative_result == native_result if isinstance(
            alternative_result, float) else are_alternative_native_ints_equal(
                alternative_result, native_result))
Esempio n. 11
0
def test_no_argument() -> None:
    alternative, native = AlternativeInt(), NativeInt()

    assert are_alternative_native_ints_equal(alternative, native)
Esempio n. 12
0
def test_basic(pair: AlternativeNativeIntsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_ints_equal(math.floor(alternative),
                                             math.floor(native))
Esempio n. 13
0
def test_decimal_string(string: str) -> None:
    alternative, native = AlternativeInt(string), NativeInt(string)

    assert are_alternative_native_ints_equal(alternative, native)
Esempio n. 14
0
def test_basic(pair: AlternativeNativeFractionsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_ints_equal(math.ceil(alternative),
                                             math.ceil(native))
Esempio n. 15
0
def test_basic(pair: AlternativeNativeIntsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_ints_equal(alternative.bit_length(),
                                             native.bit_length())
Esempio n. 16
0
def test_basic(pair: AlternativeNativeIntsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_ints_equal(+alternative, +native)
Esempio n. 17
0
def test_basic(pair: AlternativeNativeIntsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_ints_equal(pickle_round_trip(alternative),
                                             pickle_round_trip(native))
Esempio n. 18
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)