<commit_before><?php

namespace test\Monad;

use Widmogrod\FantasyLand\Applicative;
use Widmogrod\FantasyLand\Functor;
use Widmogrod\Helpful\ApplicativeLaws;
use Widmogrod\Helpful\FunctorLaws;
use Widmogrod\Helpful\MonoidLaws;
use Widmogrod\Monad\Maybe;
use Widmogrod\Monad\Maybe\Just;
use Widmogrod\Monad\Maybe\Nothing;
use Widmogrod\Helpful\MonadLaws;
use Widmogrod\Functional as f;
use Widmogrod\Primitive\Listt;

class MaybeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider provideData
     */
    public function test_if_maybe_monad_obeys_the_laws($return, $f, $g, $x)
    {
        MonadLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            f\curryN(1, $return),
            $f,
            $g,
            $x
        );
    }

    public function provideData()
    {
        return [
            'Just' => [
                '$return' => Just::of,
                '$f'      => function ($x) {
                    return Just::of($x + 1);
                },
                '$g' => function ($x) {
                    return Just::of($x + 2);
                },
                '$x' => 10,
            ],
            'Nothing' => [
                '$return' => Nothing::of,
                '$f'      => function ($x) {
                    return Nothing::of($x + 1);
                },
                '$g' => function ($x) {
                    return Nothing::of($x + 2);
                },
                '$x' => 10,
            ],
        ];
    }

    /**
     * @dataProvider provideApplicativeTestData
     */
    public function test_it_should_obey_applicative_laws(
        $pure,
        Applicative $u,
        Applicative $v,
        Applicative $w,
        callable $f,
        $x
    ) {
        ApplicativeLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            f\curryN(1, $pure),
            $u,
            $v,
            $w,
            $f,
            $x
        );
    }

    public function provideApplicativeTestData()
    {
        return [
            'Just' => [
                '$pure' => Maybe\pure,
                '$u'    => Just::of(function () {
                    return 1;
                }),
                '$v' => Just::of(function () {
                    return 5;
                }),
                '$w' => Just::of(function () {
                    return 7;
                }),
                '$f' => function ($x) {
                    return $x + 400;
                },
                '$x' => 33
            ],
            'Nothing' => [
                '$pure' => Maybe\pure,
                '$u'    => Nothing::of(function () {
                    return 1;
                }),
                '$v' => Nothing::of(function () {
                    return 5;
                }),
                '$w' => Nothing::of(function () {
                    return 7;
                }),
                '$f' => function ($x) {
                    return $x + 400;
                },
                '$x' => 33
            ],
        ];
    }

    /**
     * @dataProvider provideMonoidTestData
     */
    public function test_it_should_obey_monoid_laws($x, $y, $z)
    {
        MonoidLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            $x, $y, $z
        );
    }

    public function provideMonoidTestData()
    {
        return [
            'Just' => [
                '$x' => Just::of(Listt::of(1)),
                '$y' => Just::of(Listt::of(2)),
                '$z' => Just::of(Listt::of(3))
            ],
            'Nothing' => [
                '$x' => Nothing::of(null),
                '$y' => Nothing::of(null),
                '$z' => Nothing::of(null)
            ]
        ];<commit_msg>Provide more test examples to Maybe Monoid<commit_after><?php

namespace test\Monad;

use Widmogrod\FantasyLand\Applicative;
use Widmogrod\FantasyLand\Functor;
use Widmogrod\Helpful\ApplicativeLaws;
use Widmogrod\Helpful\FunctorLaws;
use Widmogrod\Helpful\MonoidLaws;
use Widmogrod\Monad\Maybe;
use Widmogrod\Monad\Maybe\Just;
use Widmogrod\Monad\Maybe\Nothing;
use Widmogrod\Helpful\MonadLaws;
use Widmogrod\Functional as f;
use Widmogrod\Primitive\Listt;
use Widmogrod\Primitive\Stringg;

class MaybeTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @dataProvider provideData
     */
    public function test_if_maybe_monad_obeys_the_laws($return, $f, $g, $x)
    {
        MonadLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            f\curryN(1, $return),
            $f,
            $g,
            $x
        );
    }

    public function provideData()
    {
        return [
            'Just' => [
                '$return' => Just::of,
                '$f'      => function ($x) {
                    return Just::of($x + 1);
                },
                '$g' => function ($x) {
                    return Just::of($x + 2);
                },
                '$x' => 10,
            ],
            'Nothing' => [
                '$return' => Nothing::of,
                '$f'      => function ($x) {
                    return Nothing::of($x + 1);
                },
                '$g' => function ($x) {
                    return Nothing::of($x + 2);
                },
                '$x' => 10,
            ],
        ];
    }

    /**
     * @dataProvider provideApplicativeTestData
     */
    public function test_it_should_obey_applicative_laws(
        $pure,
        Applicative $u,
        Applicative $v,
        Applicative $w,
        callable $f,
        $x
    ) {
        ApplicativeLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            f\curryN(1, $pure),
            $u,
            $v,
            $w,
            $f,
            $x
        );
    }

    public function provideApplicativeTestData()
    {
        return [
            'Just' => [
                '$pure' => Maybe\pure,
                '$u'    => Just::of(function () {
                    return 1;
                }),
                '$v' => Just::of(function () {
                    return 5;
                }),
                '$w' => Just::of(function () {
                    return 7;
                }),
                '$f' => function ($x) {
                    return $x + 400;
                },
                '$x' => 33
            ],
            'Nothing' => [
                '$pure' => Maybe\pure,
                '$u'    => Nothing::of(function () {
                    return 1;
                }),
                '$v' => Nothing::of(function () {
                    return 5;
                }),
                '$w' => Nothing::of(function () {
                    return 7;
                }),
                '$f' => function ($x) {
                    return $x + 400;
                },
                '$x' => 33
            ],
        ];
    }

    /**
     * @dataProvider provideMonoidTestData
     */
    public function test_it_should_obey_monoid_laws($x, $y, $z)
    {
        MonoidLaws::test(
            f\curryN(3, [$this, 'assertEquals']),
            $x, $y, $z
        );
    }

    public function provideMonoidTestData()
    {
        return [
            'Just' => [
                '$x' => Just::of(Listt::of(1)),
                '$y' => Just::of(Listt::of(2)),
                '$z' => Just::of(Listt::of(3))
            ],
            'Nothing' => [
                '$x' => Nothing::mempty(),
                '$y' => Nothing::mempty(),
                '$z' => Nothing::mempty(),
            ],
            'Just String' => [
                '$x' => Just::of(Stringg::of("Hello")),
                '$y' => Just::of(Stringg::of(" ")),
                '$z' => Just::of(Stringg::of("World"))
            ],
            'Maybe String' => [
                '$x' => Just::of(Stringg::of("Hello")),
                '$y' => Nothing::mempty(),
                '$z' => Just::of(Stringg::of("World"))
            ],
        ];
{'fraction_non_alphanumeric': 0.1520754716981132, 'fraction_numerical': 0.008050314465408805, 'mean_word_length': 1.1236645299145298, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '7555608', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2297, 'n_words': 412}