PHP code example of innmind / black-box

1. Go to this page and download the library: Download innmind/black-box library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

innmind / black-box example snippets


use Innmind\BlackBox\{
    Application,
    Set,
    Runner\Assert,
};

Application::new([])
    ->tryToProve(static function() {
        yield proof(
            'add is commutative',
            given(
                Set\Integers::any(),
                Set\Integers::any(),
            ),
            static fn(Assert $assert, int $a, int $b) => $assert->same(
                add($a, $b),
                add($b, $a),
            ),
        );
        yield proof(
            'add is associative',
            given(
                Set\Integers::any(),
                Set\Integers::any(),
                Set\Integers::any(),
            ),
            static fn(Assert $assert, int $a, int $b, int $c) => $assert->same(
                add(add($a, $b), $c),
                add($a, add($b, $c)),
            ),
        );
        yield proof(
            'add is an identity function',
            given(Set\Integers::any()),
            static fn(Assert $assert, int $a) => $assert->same(
                $a,
                add($a, 0),
            ),
        );
    })
    ->exit();