<commit_before>from hypothesis import given
from hypothesis.strategies import text, integers, booleans

from testers.semigroup_law_tester import SemigroupLawTester

from pymonet.semigroups import Sum, All, First, Map
from pymonet.utils import identity

ingredient1 = Map({'score': Sum(1), 'won': All(True), 'captain': First('captain america')})
ingredient2 = Map({'score': Sum(2), 'won': All(True), 'captain': First('iron man')})
ingredient3 = Map({'score': Sum(3), 'won': All(False), 'captain': First('Batman')})


@given(integers(), integers(), integers())
def test_sum(x, y, z):
    SemigroupLawTester(
        semigroup=Sum,
        value1=x,
        value2=y,
        value3=z,
        result=Sum(x + y + z)
    ).test()


@given(booleans(), booleans(), booleans())
def test_all(bool1, bool2, bool3):
    SemigroupLawTester(
        semigroup=All,
        value1=bool1,
        value2=bool2,
        value3=bool3,
        result=All(bool1 and bool2 and bool3)
    ).test()


@given(text(), text(), text())
def test_first(text1, text2, text3):
    SemigroupLawTester(
        semigroup=First,
        value1=text1,
        value2=text2,
        value3=text3,
        result=First(text1)
    ).test()


def test_map():
    assert ingredient1.concat(ingredient2) == Map(
        {'score': Sum(3), 'won': All(True), 'captain': First('captain america')}
    )

    assert ingredient1.concat(ingredient2).concat(ingredient3) == Map(
        {'score': Sum(6), 'won': All(False), 'captain': First('captain america')}
    )

    assert ingredient1.concat(ingredient2.concat(ingredient3)) == Map(
        {'score': Sum(6), 'won': All(False), 'captain': First('captain america')}
    )


@given(integers(), text(), booleans())
def test_fold(integer, text, boolean):

    dictionary = {'key': 'value'}

    assert First(text).fold(identity) is text
    assert All(boolean).fold(identity) is boolean
    assert Sum(integers).fold(identity) is integers
    assert Map(dictionary).fold(identity) is dictionary<commit_msg>apply hypothesis on semigroun map test<commit_after>from hypothesis import given
from hypothesis.strategies import text, integers, booleans, dictionaries

from testers.semigroup_law_tester import SemigroupLawTester

from pymonet.semigroups import Sum, All, First, Map
from pymonet.utils import identity

ingredient1 = Map({'score': Sum(1), 'won': All(True), 'captain': First('captain america')})
ingredient2 = Map({'score': Sum(2), 'won': All(True), 'captain': First('iron man')})
ingredient3 = Map({'score': Sum(3), 'won': All(False), 'captain': First('Batman')})


@given(integers(), integers(), integers())
def test_sum(x, y, z):
    SemigroupLawTester(
        semigroup=Sum,
        value1=x,
        value2=y,
        value3=z,
        result=Sum(x + y + z)
    ).test()


@given(booleans(), booleans(), booleans())
def test_all(bool1, bool2, bool3):
    SemigroupLawTester(
        semigroup=All,
        value1=bool1,
        value2=bool2,
        value3=bool3,
        result=All(bool1 and bool2 and bool3)
    ).test()


@given(text(), text(), text())
def test_first(text1, text2, text3):
    SemigroupLawTester(
        semigroup=First,
        value1=text1,
        value2=text2,
        value3=text3,
        result=First(text1)
    ).test()


@given(
    integers(), integers(), integers(),
    booleans(), booleans(), booleans(),
    text(), text(), text()
)
def test_map(integer1, integer2, integer3, boolean1, boolean2, boolean3, text1, text2, text3):
    SemigroupLawTester(
        semigroup=Map,
        value1={ 'sum': Sum(integer1), 'all': All(boolean1), 'first': First(text1) },
        value2={ 'sum': Sum(integer2), 'all': All(boolean2), 'first': First(text2) },
        value3={ 'sum': Sum(integer3), 'all': All(boolean3), 'first': First(text3) },
        result=Map({
            'sum': Sum(integer1 + integer2 + integer3),
            'all': All(boolean1 and boolean2 and boolean3),
            'first': First(text1)
        })
    ).test()

@given(integers(), text(), booleans(), dictionaries(keys=text(), values=integers()))
def test_fold(integer, text, boolean, dictionary):

    assert First(text).fold(identity) is text
    assert All(boolean).fold(identity) is boolean
    assert Sum(integers).fold(identity) is integers
    assert Map(dictionary).fold(identity) is dictionary
{'fraction_non_alphanumeric': 0.15806526267067808, 'fraction_numerical': 0.023374218930803055, 'mean_word_length': 3.8236607142857144, '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': '5362525', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1429, 'n_words': 338}