<commit_before>import sys
import pytest
import _gmpy

class TestInit(object):
    small_ints = {-1, 0, 1, 123, -9876, sys.maxint, -sys.maxint - 1}
    big_ints = {sys.maxint + 1, -sys.maxint - 2, 2 * sys.maxint + 1, 2 * sys.maxint + 2}

    def _test_init(self, numbers):
        for n in numbers:
            assert _gmpy.mpz(n) == n

    def test_init_smallint(self):
        self._test_init(self.small_ints)

    def test_init_bigint(self):
        self._test_init(self.big_ints)

    def test_init_float(self):
        for f in {0.0, 1.0, 1.5, 1e15 + 0.9}:
            assert _gmpy.mpz(f) == int(f)
            assert _gmpy.mpz(-f) == int(-f)

    def test_init_small_decimal_str(self):
        for n in self.small_ints:
            assert _gmpy.mpz(str(n), 10) == n
            assert _gmpy.mpz(str(n)) == n
            assert _gmpy.mpz(str(n), 0) == n

    def test_init_big_decimal_str(self):
        for n in self.big_ints:
            assert _gmpy.mpz(str(n), 10) == n
            assert _gmpy.mpz(str(n)) == n
            assert _gmpy.mpz(str(n), 0) == n

    def test_init_small_hex_str(self):
        for n in self.small_ints:
            assert _gmpy.mpz("%x" % n, 16) == n
            assert _gmpy.mpz("%#x" % n, 0) == n

    def test_init_big_hex_str(self):
        for n in self.big_ints:
            assert _gmpy.mpz("%x" % n, 16) == n
            assert _gmpy.mpz("%#x" % n, 0) == n

    def test_init_invalid(self):
        for n, base in {('0x1', 16), ('g', 16), ('a', 10)}:
            with pytest.raises(ValueError):
                _gmpy.mpz(n, base)

class TestMath(object):
    numbers = {(0, 1), (23, 42), (sys.maxint, sys.maxint), (sys.maxint, 1)}

    def test_add(self):
        for a, b in self.numbers:
            assert _gmpy.mpz(a) + _gmpy.mpz(b) == _gmpy.mpz(a + b)
            assert _gmpy.mpz(a) + b == _gmpy.mpz(a + b)
            assert b + _gmpy.mpz(a) == _gmpy.mpz(b + a)
            assert (-a) + _gmpy.mpz(b) == _gmpy.mpz(-a + b)
            assert _gmpy.mpz(a) + (-b) == _gmpy.mpz(a - b)

    def test_sub(self):
        for a, b in self.numbers:
            assert _gmpy.mpz(a) - _gmpy.mpz(b) == _gmpy.mpz(a - b)
            assert _gmpy.mpz(a) - b == _gmpy.mpz(a - b)
            assert a - _gmpy.mpz(b) == _gmpy.mpz(a - b)
            #assert (-a) - _gmpy.mpz(b) == _gmpy.mpz(-a - b)
            assert _gmpy.mpz(a) - (-b) == _gmpy.mpz(a + b)<commit_msg>Use pytest.mark.parametrize instead of loops, mark TestMath.test_sub as conditional xfail<commit_after>import sys
import pytest
import _gmpy

class TestInit(object):
    small_ints = {-1, 0, 1, 123, -9876, sys.maxint, -sys.maxint - 1}
    big_ints = {sys.maxint + 1, -sys.maxint - 2, 2 * sys.maxint + 1, 2 * sys.maxint + 2}

    @pytest.mark.parametrize('n', small_ints.union(big_ints))
    def test_init_int(self, n):
        assert _gmpy.mpz(n) == n

    @pytest.mark.parametrize('f', {0.0, 1.0, 1.5, 1e15 + 0.9})
    def test_init_float(self, f):
        assert _gmpy.mpz(f) == int(f)
        assert _gmpy.mpz(-f) == int(-f)

    @pytest.mark.parametrize('n', small_ints.union(big_ints))
    def test_init_decimal_str(self, n):
        assert _gmpy.mpz(str(n), 10) == n
        assert _gmpy.mpz(str(n)) == n
        assert _gmpy.mpz(str(n), 0) == n

    @pytest.mark.parametrize('n', small_ints.union(big_ints))
    def test_init_hex_str(self, n):
        assert _gmpy.mpz("%x" % n, 16) == n
        assert _gmpy.mpz("%#x" % n, 0) == n

    @pytest.mark.parametrize(('n', 'base'), {('0x1', 16), ('g', 16), ('a', 10)})
    def test_init_invalid(self, n, base):
        with pytest.raises(ValueError):
            _gmpy.mpz(n, base)

class TestMath(object):
    numbers = {(0, 1), (23, 42), (sys.maxint, sys.maxint), (sys.maxint, 1)}

    @pytest.mark.parametrize(('a', 'b'), numbers)
    def test_add(self, a, b):
        assert _gmpy.mpz(a) + _gmpy.mpz(b) == _gmpy.mpz(a + b)
        assert _gmpy.mpz(a) + b == _gmpy.mpz(a + b)
        assert b + _gmpy.mpz(a) == _gmpy.mpz(b + a)
        assert (-a) + _gmpy.mpz(b) == _gmpy.mpz(-a + b)
        assert _gmpy.mpz(a) + (-b) == _gmpy.mpz(a - b)

    @pytest.mark.parametrize(('a', 'b'), numbers)
    def test_sub(self, a, b):
        if a:
            pytest.xfail('a != 0')
        assert _gmpy.mpz(a) - _gmpy.mpz(b) == _gmpy.mpz(a - b)
        assert _gmpy.mpz(a) - b == _gmpy.mpz(a - b)
        assert a - _gmpy.mpz(b) == _gmpy.mpz(a - b)
        assert (-a) - _gmpy.mpz(b) == _gmpy.mpz(-a - b)
        assert _gmpy.mpz(a) - (-b) == _gmpy.mpz(a + b)
{'fraction_non_alphanumeric': 0.17681030653043092, 'fraction_numerical': 0.023322967569968902, 'mean_word_length': 2.198153409090909, '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': '610470', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1969, 'n_words': 402}