<commit_before><?php

namespace Tests\Chromabits\Nucleus\Control;

use Chromabits\Nucleus\Control\MaybeMonad;
use Chromabits\Nucleus\Testing\TestCase;

/**
 * Class MaybeMonadTest
 *
 * @author <NAME> <<EMAIL>>
 * @package Tests\Chromabits\Nucleus\Control
 */
class MaybeMonadTest extends TestCase
{
    public function testBind()
    {
        $getUser = function ($id) {
            if ($id === 5) {
                return MaybeMonad::just([
                    'first_name' => 'Bob',
                ]);
            }

            return MaybeMonad::nothing();
        };

        $getFirstName = function (array $user) {
            return MaybeMonad::just($user['first_name']);
        };

        $result1 = $getUser(5)->bind($getFirstName);
        $result2 = $getUser(4)->bind($getFirstName);

        $this->assertTrue($result1->isJust());
        $this->assertTrue($result2->isNothing());
        $this->assertEquals('Bob', MaybeMonad::fromJust($result1));
    }
}<commit_msg>Add more tests for MaybeMonad<commit_after><?php

namespace Tests\Chromabits\Nucleus\Control;

use Chromabits\Nucleus\Control\MaybeMonad;
use Chromabits\Nucleus\Testing\TestCase;

/**
 * Class MaybeMonadTest
 *
 * @author <NAME> <<EMAIL>>
 * @package Tests\Chromabits\Nucleus\Control
 */
class MaybeMonadTest extends TestCase
{
    public function testBind()
    {
        $getUser = function ($id) {
            if ($id === 5) {
                return MaybeMonad::just([
                    'first_name' => 'Bob',
                ]);
            }

            return MaybeMonad::nothing();
        };

        $getFirstName = function (array $user) {
            return MaybeMonad::just($user['first_name']);
        };

        $lowerCase = function ($string) {
            return MaybeMonad::just(strtolower($string));
        };

        $result1 = $getUser(5)->bind($getFirstName);
        $result2 = $getUser(4)->bind($getFirstName);
        $result3 = $getUser(5)->bind($getFirstName)->bind($lowerCase);
        $result4 = $getUser(4)->bind($getFirstName)->bind($lowerCase);

        $this->assertTrue($result1->isJust());
        $this->assertTrue($result2->isNothing());
        $this->assertTrue($result3->isJust());
        $this->assertTrue($result4->isNothing());
        $this->assertEquals('Bob', MaybeMonad::fromJust($result1));
        $this->assertEquals('bob', MaybeMonad::fromJust($result3));
    }

    public function testLeftIdentity()
    {
        // TODO: Ensure this is the right way to test this.
        $lowerCase = function ($string) {
            return MaybeMonad::just(strtolower($string));
        };

        $this->assertEquals(
            MaybeMonad::unit('SomeValue')->bind($lowerCase),
            $lowerCase('SomeValue')
        );
        $this->assertEquals(
            MaybeMonad::unit(null)->bind($lowerCase),
            $lowerCase(null)
        );
    }

    public function testRightIdentity()
    {
        // TODO: Ensure this is the right way to test this.
        $m = MaybeMonad::unit('doge');

        $this->assertEquals(
            $m->bind(function ($x) {
                return MaybeMonad::unit($x);
            }),
            $m
        );

        $this->assertTrue(
            $m->bind(function ($x) {
                return MaybeMonad::unit($x);
            }) == $m
        );
    }
}
{'fraction_non_alphanumeric': 0.1569332135369871, 'fraction_numerical': 0.006888289907157832, 'mean_word_length': 2.2053742802303264, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, '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': '3221278', 'n_tokens_mistral': 1004, 'n_tokens_neox': 972, 'n_words': 162}