<commit_before>from sympy.rules.rl import rm_id, glom, flatten, unpack, sort, distribute
from sympy import Basic

def test_rm_id():
    rmzeros = rm_id(lambda x: x == 0)
    assert rmzeros(Basic(0, 1)) == Basic(1)
    assert rmzeros(Basic(0, 0)) == Basic(0)
    assert rmzeros(Basic(2, 1)) == Basic(2, 1)

def test_glom():
    from sympy import Add
    from sympy.abc import x
    key     = lambda x: x.as_coeff_Mul()[1]
    count   = lambda x: x.as_coeff_Mul()[0]
    newargs = lambda cnt, arg: cnt * arg
    rl = glom(key, count, newargs)

    assert rl(Add(x, -x, 3*x, 2, 3, evaluate=False)) == 3*x + 5

def test_flatten():
    assert flatten(Basic(1, 2, Basic(3, 4))) == Basic(1, 2, 3, 4)

def test_unpack():
    assert unpack(Basic(2)) == 2

def test_sort():
    assert sort(str)(Basic(3,1,2)) == Basic(1,2,3)

def test_distribute():
    class T1(Basic):        pass
    class T2(Basic):        pass

    distribute_t12 = distribute(T1, T2)
    assert distribute_t12(T1(1, 2, T2(3, 4), 5)) == \
            T2(T1(1, 2, 3, 5),
               T1(1, 2, 4, 5))

def test_distribute_add_mul():<commit_msg>test_glom no longer sensitive to randomness<commit_after>from sympy.rules.rl import rm_id, glom, flatten, unpack, sort, distribute
from sympy import Basic

def test_rm_id():
    rmzeros = rm_id(lambda x: x == 0)
    assert rmzeros(Basic(0, 1)) == Basic(1)
    assert rmzeros(Basic(0, 0)) == Basic(0)
    assert rmzeros(Basic(2, 1)) == Basic(2, 1)

def test_glom():
    from sympy import Add
    from sympy.abc import x
    key     = lambda x: x.as_coeff_Mul()[1]
    count   = lambda x: x.as_coeff_Mul()[0]
    newargs = lambda cnt, arg: cnt * arg
    rl = glom(key, count, newargs)

    result   = rl(Add(x, -x, 3*x, 2, 3, evaluate=False))
    expected = Add(3*x, 5)
    assert  set(result.args) == set(expected.args)

def test_flatten():
    assert flatten(Basic(1, 2, Basic(3, 4))) == Basic(1, 2, 3, 4)

def test_unpack():
    assert unpack(Basic(2)) == 2

def test_sort():
    assert sort(str)(Basic(3,1,2)) == Basic(1,2,3)

def test_distribute():
    class T1(Basic):        pass
    class T2(Basic):        pass

    distribute_t12 = distribute(T1, T2)
    assert distribute_t12(T1(1, 2, T2(3, 4), 5)) == \
            T2(T1(1, 2, 3, 5),
               T1(1, 2, 4, 5))

def test_distribute_add_mul():
{'fraction_non_alphanumeric': 0.15750757247944613, 'fraction_numerical': 0.05192557334487235, 'mean_word_length': 3.099290780141844, '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': '4485226', 'n_tokens_mistral': 974, 'n_tokens_neox': 913, 'n_words': 244}