<commit_before>from __future__ import division

import sys
import pytest
from gmpy_cffi import mpq, mpz



class TestInit(object):
    ints = [1, -1, 2, -123, 456, sys.maxsize, -sys.maxsize - 1, 2*sys.maxsize, -2*sys.maxsize]
    floats = [0.0, 1.0, 1.5, 1e15 + 0.9, -1.5e15 + 0.9]
    int_pairs = [(i,j) for i in ints for j in ints]

    # Length 0
    def test_init_empty(self):
        assert mpq() == mpq(0, 1)

    # Length 1
    @pytest.mark.parametrize('n', ints)
    def test_init_int1(self, n):
        assert mpq(n) == n

    @pytest.mark.parametrize('f', floats)
    def test_init_float1(self, f):
        assert float(mpq(f)) == f
        assert float(mpq(-f)) == -f

    @pytest.mark.parametrize(('n', 'd'), int_pairs)
    def test_init_mpq1(self, n, d):
        assert mpq(mpq(n, d)) == mpq(n, d)

    @pytest.mark.parametrize('type_', [int, float, mpz, mpq, str])
    def test_init_type(self, type_):
        assert mpq(type_(1)) == 1

    @pytest.mark.parametrize('n', [[], set([])])
    def test_init_single_invalid(self, n):
        with pytest.raises(TypeError):
            mpq(n)

    @pytest.mark.parametrize('n', [1])# floats + [mpz(1), mpq(1, 2)])
    def test_init_zero_den(self, n):
        with pytest.raises(ZeroDivisionError):
            mpq(n, 0)

    # Length 2
    @pytest.mark.parametrize(('n', 'd'), [(1, 1), (-1, 1), (1, -1), (-1, -1)])
    def test_init_sign(self, n, d):
        assert mpq(n, d) == n // d

    @pytest.mark.parametrize(('n', 'd'), int_pairs)
    def test_init_str(self, n, d):
        assert mpq('%s/%s' % (n, d)) == mpq(n, d)
        assert mpq(1, mpq(n, d)) == mpq(d, n)

    def test_init_int2(self):
        assert mpq(3, 6) == mpq(1, 2)
        assert mpq(2, sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(4, 2*sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(8, 4*sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(3, mpz(5)) == mpq(3, 5)
        assert mpq(3, mpq(5, 7)) == mpq(21, 5)
        assert mpq(3, 0.5) == mpq(6, 1)
        assert mpq(3, 0.6) == mpq(27021597764222976,5404319552844595)

        assert mpq(sys.maxsize, 6) == mpq(sys.maxsize, 6)
        assert mpq(sys.maxsize, sys.maxsize) == mpq(1, 1)
        assert mpq(sys.maxsize, 2*sys.maxsize) == mpq(1, 2)
        assert mpq(sys.maxsize, 4*sys.maxsize) == mpq(1, 4)
        assert mpq(sys.maxsize, mpz(5)) == mpq(sys.maxsize, 5)
        assert mpq(sys.maxsize, mpq(5, 7)) == mpq(7*sys.maxsize, 5)
        assert mpq(sys.maxsize, 0.5) == mpq(2*sys.maxsize, 1)
        assert mpq(sys.maxsize, 0.6) == mpq(9007199254740992*sys.maxsize, 5404319552844595)

        assert mpq(2*sys.maxsize, 6) == mpq(2*sys.maxsize, 6)
        assert mpq(2*sys.maxsize, sys.maxsize) == mpq(2, 1)<commit_msg>don't import __future__.division in mpq tests<commit_after>import sys
import pytest
from gmpy_cffi import mpq, mpz



class TestInit(object):
    ints = [1, -1, 2, -123, 456, sys.maxsize, -sys.maxsize - 1, 2*sys.maxsize, -2*sys.maxsize]
    floats = [0.0, 1.0, 1.5, 1e15 + 0.9, -1.5e15 + 0.9]
    int_pairs = [(i,j) for i in ints for j in ints]

    # Length 0
    def test_init_empty(self):
        assert mpq() == mpq(0, 1)

    # Length 1
    @pytest.mark.parametrize('n', ints)
    def test_init_int1(self, n):
        assert mpq(n) == n

    @pytest.mark.parametrize('f', floats)
    def test_init_float1(self, f):
        assert float(mpq(f)) == f
        assert float(mpq(-f)) == -f

    @pytest.mark.parametrize(('n', 'd'), int_pairs)
    def test_init_mpq1(self, n, d):
        assert mpq(mpq(n, d)) == mpq(n, d)

    @pytest.mark.parametrize('type_', [int, float, mpz, mpq, str])
    def test_init_type(self, type_):
        assert mpq(type_(1)) == 1

    @pytest.mark.parametrize('n', [[], set([])])
    def test_init_single_invalid(self, n):
        with pytest.raises(TypeError):
            mpq(n)

    @pytest.mark.parametrize('n', [1])# floats + [mpz(1), mpq(1, 2)])
    def test_init_zero_den(self, n):
        with pytest.raises(ZeroDivisionError):
            mpq(n, 0)

    # Length 2
    @pytest.mark.parametrize(('n', 'd'), [(1, 1), (-1, 1), (1, -1), (-1, -1)])
    def test_init_sign(self, n, d):
        assert mpq(n, d) == n / d

    @pytest.mark.parametrize(('n', 'd'), int_pairs)
    def test_init_str(self, n, d):
        assert mpq('%s/%s' % (n, d)) == mpq(n, d)
        assert mpq(1, mpq(n, d)) == mpq(d, n)

    def test_init_int2(self):
        assert mpq(3, 6) == mpq(1, 2)
        assert mpq(2, sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(4, 2*sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(8, 4*sys.maxsize) == mpq(2, sys.maxsize)
        assert mpq(3, mpz(5)) == mpq(3, 5)
        assert mpq(3, mpq(5, 7)) == mpq(21, 5)
        assert mpq(3, 0.5) == mpq(6, 1)
        assert mpq(3, 0.6) == mpq(27021597764222976,5404319552844595)

        assert mpq(sys.maxsize, 6) == mpq(sys.maxsize, 6)
        assert mpq(sys.maxsize, sys.maxsize) == mpq(1, 1)
        assert mpq(sys.maxsize, 2*sys.maxsize) == mpq(1, 2)
        assert mpq(sys.maxsize, 4*sys.maxsize) == mpq(1, 4)
        assert mpq(sys.maxsize, mpz(5)) == mpq(sys.maxsize, 5)
        assert mpq(sys.maxsize, mpq(5, 7)) == mpq(7*sys.maxsize, 5)
        assert mpq(sys.maxsize, 0.5) == mpq(2*sys.maxsize, 1)
        assert mpq(sys.maxsize, 0.6) == mpq(9007199254740992*sys.maxsize, 5404319552844595)

        assert mpq(2*sys.maxsize, 6) == mpq(2*sys.maxsize, 6)
        assert mpq(2*sys.maxsize, sys.maxsize) == mpq(2, 1)
{'fraction_non_alphanumeric': 0.18516483516483517, 'fraction_numerical': 0.0652014652014652, 'mean_word_length': 2.732740943267259, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1730440', 'n_tokens_mistral': 2567, 'n_tokens_neox': 2367, 'n_words': 502}