diff --git a/composer.json b/composer.json index 93763b4..0e7cad6 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,9 @@ "phpunit/phpunit": "*" }, "autoload": { - "psr-4": { - "Pairs\\": "src" - } + "files": [ + "src/Pairs.php", + "src/Lists.php" + ] } } diff --git a/composer.lock b/composer.lock index 19ce563..4c8c5cc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "86509b22058b7ffc55258e8448472c86", - "content-hash": "9213c47d564505429c56200c93133fed", + "hash": "142419ec950cea250c7fb31febfe42b1", + "content-hash": "2baadab544344aec474df09d2b1710a4", "packages": [], "packages-dev": [ { diff --git a/phpunit b/phpunit new file mode 100644 index 0000000..ed435c9 --- /dev/null +++ b/phpunit @@ -0,0 +1,27 @@ +#!/usr/bin/env php + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +if (version_compare('5.6.0', PHP_VERSION, '>')) { + fwrite( + STDERR, + 'This version of PHPUnit requires PHP 5.6; using the latest version of PHP is highly recommended.' . PHP_EOL + ); + + die(1); +} + +if (!ini_get('date.timezone')) { + ini_set('date.timezone', 'UTC'); +} + +require __DIR__ . '/vendor/autoload.php'; + +PHPUnit_TextUI_Command::main(); diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3404601 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + + ./tests/ + + + diff --git a/src/Lists.php b/src/Lists.php new file mode 100644 index 0000000..ffa5ff2 --- /dev/null +++ b/src/Lists.php @@ -0,0 +1,102 @@ +assertEquals(3, length($list)); + + } + + public function testReverse() + { + $list = cons(1, cons(2, cons(3, null))); + $expected = toString(cons(3, cons(2, cons(1, null)))); + $this->assertEquals($expected, toString(reverse($list))); + } + + public function testMap() + { + $list = cons(1, cons(2, cons(3, null))); + $expected = toString(cons(3, cons(4, cons(5, null)))); + $map = map(function ($x) { + return $x + 2; + }, $list); + $this->assertEquals($expected, toString($map)); + } + + public function testFilter() + { + $list = cons(2, cons(3, cons(4, null))); + $expected = toString(cons(2, cons(4, null))); + $filter = filter(function ($x) { + return $x % 2 == 0; + }, $list); + + $this->assertEquals(2, length($filter)); + $this->assertEquals($expected, toString($filter)); + } + + public function testReduce() + { + $list = cons(1, cons(2, cons(3, null))); + $expected = 6; + $map = reduce(function ($x, $acc) { + return $x + $acc; + }, $list, 0); + $this->assertEquals($expected, $map); + } +} diff --git a/tests/PairsTest.php b/tests/PairsTest.php index 4a3d2c0..7e4fa80 100644 --- a/tests/PairsTest.php +++ b/tests/PairsTest.php @@ -2,8 +2,6 @@ namespace Pairs\tests; -require_once 'Pairs.php'; - use function Pairs\cons; use function Pairs\car; use function Pairs\cdr;