<commit_before>import pytest

from diofant.core import oo, Integer
from diofant.functions.elementary.miscellaneous import sqrt
from diofant.polys import poly
from diofant.polys.dispersion import dispersion, dispersionset

from diofant.abc import x, y, a

__all__ = ()


def test_dispersion():
    pytest.raises(ValueError, lambda: dispersionset(poly(x*y, x, y),
                                                    poly(x, x)))
    pytest.raises(ValueError, lambda: dispersionset(poly(x, x),
                                                    poly(y, y)))

    fp = poly(Integer(0), x)
    assert sorted(dispersionset(fp)) == [0]

    fp = poly(Integer(2), x)
    assert sorted(dispersionset(fp)) == [0]

    fp = poly(x + 1, x)
    assert sorted(dispersionset(fp)) == [0]
    assert dispersion(fp) == 0

    fp = poly((x + 1)*(x + 2), x)
    assert sorted(dispersionset(fp)) == [0, 1]
    assert dispersion(fp) == 1

    fp = poly(x*(x + 3), x)
    assert sorted(dispersionset(fp)) == [0, 3]
    assert dispersion(fp) == 3

    fp = poly((x - 3)*(x + 3), x)
    assert sorted(dispersionset(fp)) == [0, 6]
    assert dispersion(fp) == 6

    fp = poly(x**4 - 3*x**2 + 1, x)
    gp = fp.shift(-3)
    assert sorted(dispersionset(fp, gp)) == [2, 3, 4]
    assert dispersion(fp, gp) == 4
    assert sorted(dispersionset(gp, fp)) == []
    assert dispersion(gp, fp) == -oo

    fp = poly(x*(3*x**2+a)*(x-2536)*(x**3+a), x)
    gp = fp.as_expr().subs(x, x-345).as_poly(x)
    assert sorted(dispersionset(fp, gp)) == [345, 2881]
    assert sorted(dispersionset(gp, fp)) == [2191]
<commit_msg>100% coverage by tests for dispersion.py<commit_after>import pytest

from diofant.core import oo, Integer
from diofant.functions.elementary.miscellaneous import sqrt
from diofant.polys import poly
from diofant.polys.dispersion import dispersion, dispersionset

from diofant.abc import x, y, a

__all__ = ()


def test_dispersion():
    pytest.raises(ValueError, lambda: dispersionset(poly(x*y, x, y),
                                                    poly(x, x)))
    pytest.raises(ValueError, lambda: dispersionset(poly(x, x),
                                                    poly(y, y)))

    fp = poly(Integer(0), x)
    assert sorted(dispersionset(fp)) == [0]

    fp = poly(Integer(2), x)
    assert sorted(dispersionset(fp)) == [0]

    fp = poly(x + 1, x)
    assert sorted(dispersionset(fp)) == [0]
    assert dispersion(fp) == 0

    fp = poly((x + 1)*(x + 2), x)
    assert sorted(dispersionset(fp)) == [0, 1]
    assert dispersion(fp) == 1

    fp = poly(x*(x + 3), x)
    assert sorted(dispersionset(fp)) == [0, 3]
    assert dispersion(fp) == 3

    fp = poly((x - 3)*(x + 3), x)
    assert sorted(dispersionset(fp)) == [0, 6]
    assert dispersion(fp) == 6

    fp = poly(x**4 - 3*x**2 + 1, x)
    gp = fp.shift(-3)
    assert sorted(dispersionset(fp, gp)) == [2, 3, 4]
    assert dispersion(fp, gp) == 4
    assert sorted(dispersionset(gp, fp)) == []
    assert dispersion(gp, fp) == -oo

    fp = poly(x**2 + 2*x - 1, x)
    gp = poly(x**2 + 2*x + 3, x)
    assert dispersionset(fp, gp) == set()

    fp = poly(x*(3*x**2+a)*(x-2536)*(x**3+a), x)
    gp = fp.as_expr().subs(x, x-345).as_poly(x)
    assert sorted(dispersionset(fp, gp)) == [345, 2881]
    assert sorted(dispersionset(gp, fp)) == [2191]

{'fraction_non_alphanumeric': 0.1677750906892382, 'fraction_numerical': 0.03355501813784764, 'mean_word_length': 2.7179775280898877, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '960149', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1194, 'n_words': 295}