コード例 #1
0
ファイル: test_radd.py プロジェクト: lycantropos/cppbuiltins
def test_basic(first_pair: AlternativeNativeIntsPair,
               second_pair: AlternativeNativeFractionsPair) -> 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_fractions_equal(alternative_result,
                                                  native_result)
コード例 #2
0
def test_basic(dividends_pair: AlternativeNativeIntsPair,
               divisors_pair: AlternativeNativeFractionsPair) -> 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_fractions_equal(alternative_result,
                                                      native_result)
コード例 #3
0
def test_basic(dividends_pair: AlternativeNativeFractionsPair,
               divisors_pair: AlternativeNativeFractionsPair) -> 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_fractions_equal(alternative_remainder,
                                                      native_remainder)
コード例 #4
0
ファイル: test_pow.py プロジェクト: lycantropos/cppbuiltins
def test_basic(
    bases_pair: AlternativeNativeIntsPair,
    exponents_pair: Union[AlternativeNativeFractionsPair,
                          AlternativeNativeIntsPair]
) -> None:
    alternative_base, native_base = bases_pair
    alternative_exponent, native_exponent = exponents_pair

    try:
        alternative_result = alternative_base**alternative_exponent
    except (ValueError, ZeroDivisionError) as error:
        with pytest.raises(type(error)):
            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_fractions_equal(
                    alternative_result, native_result))
コード例 #5
0
ファイル: test_rpow.py プロジェクト: lycantropos/cppbuiltins
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)))
コード例 #6
0
def test_basic(pair: AlternativeNativeFractionsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_fractions_equal(
        pickle_round_trip(alternative), pickle_round_trip(native))
コード例 #7
0
ファイル: test_pos.py プロジェクト: lycantropos/cppbuiltins
def test_basic(pair: AlternativeNativeFractionsPair) -> None:
    alternative, native = pair

    assert are_alternative_native_fractions_equal(+alternative, +native)