From 9d009dd3e900e19588230f2526ae8ab6989f941d Mon Sep 17 00:00:00 2001 From: Federico Caprari Date: Wed, 27 Sep 2017 18:31:01 +0200 Subject: [PATCH] ripristinato codice Qaribu e aggiunti benchmarks php --- php/composer.json | 6 +- php/composer.lock | 755 +++++++++++++++++- php/phpbench.json | 5 + ...roFP.php => KataZeroLaravelCollection.php} | 2 +- .../LambdaRoma/KataZero/KataZeroQaribu.php | 147 ++++ .../benchmarks/LambdaRoma/KataZeroBench.php | 83 ++ .../KataZeroLaravelCollectionBench.php | 83 ++ .../LambdaRoma/KataZeroQaribuBench.php | 83 ++ ....php => KataZeroLaravelCollectionSpec.php} | 6 +- .../KataZero/KataZeroQaribuSpec.php | 98 +++ 10 files changed, 1259 insertions(+), 9 deletions(-) create mode 100644 php/phpbench.json rename php/src/LambdaRoma/KataZero/{KataZeroFP.php => KataZeroLaravelCollection.php} (98%) create mode 100644 php/src/LambdaRoma/KataZero/KataZeroQaribu.php create mode 100644 php/src/benchmarks/LambdaRoma/KataZeroBench.php create mode 100644 php/src/benchmarks/LambdaRoma/KataZeroLaravelCollectionBench.php create mode 100644 php/src/benchmarks/LambdaRoma/KataZeroQaribuBench.php rename php/src/spec/LambdaRoma/KataZero/{KataZeroFPSpec.php => KataZeroLaravelCollectionSpec.php} (93%) create mode 100644 php/src/spec/LambdaRoma/KataZero/KataZeroQaribuSpec.php diff --git a/php/composer.json b/php/composer.json index 2378496..9bd39be 100644 --- a/php/composer.json +++ b/php/composer.json @@ -3,7 +3,8 @@ "type": "tutorial", "require-dev": { "phpspec/phpspec": "^3.0", - "phpspec/nyan-formatters": "^2.0" + "phpspec/nyan-formatters": "^2.0", + "phpbench/phpbench": "@dev" }, "config": { "bin-dir": "bin" @@ -21,6 +22,7 @@ } ], "require": { - "tightenco/collect": "^5.5" + "tightenco/collect": "^5.5", + "qaribou/immutable.php": "^1.1" } } diff --git a/php/composer.lock b/php/composer.lock index 61f4f58..8980fd0 100644 --- a/php/composer.lock +++ b/php/composer.lock @@ -4,9 +4,56 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "59b8f45a0aa35c391661653c52d03390", - "content-hash": "27f95dd85c9c37bb5cd47de2559c94c8", + "hash": "315b3225371cfe7e64597f5c4604610a", + "content-hash": "80a3f2316cae6af8eedebec2226e11d5", "packages": [ + { + "name": "qaribou/immutable.php", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/jkoudys/immutable.php.git", + "reference": "2db1a382dec68ded17fdcc876e2c4ac363b08565" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jkoudys/immutable.php/zipball/2db1a382dec68ded17fdcc876e2c4ac363b08565", + "reference": "2db1a382dec68ded17fdcc876e2c4ac363b08565", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Qaribou\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joshua Koudys", + "email": "josh@qaribou.com", + "role": "Developer" + } + ], + "description": "Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.", + "homepage": "http://github.com/jkoudys/immutable.php", + "keywords": [ + "PHP7", + "collections", + "data structures", + "fp", + "functional", + "immutable", + "splfixedarray" + ], + "time": "2016-12-19 21:23:40" + }, { "name": "tightenco/collect", "version": "v5.5.13", @@ -56,6 +103,160 @@ } ], "packages-dev": [ + { + "name": "beberlei/assert", + "version": "v2.7.6", + "source": { + "type": "git", + "url": "https://github.com/beberlei/assert.git", + "reference": "8726e183ebbb0169cb6cb4832e22ebd355524563" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/beberlei/assert/zipball/8726e183ebbb0169cb6cb4832e22ebd355524563", + "reference": "8726e183ebbb0169cb6cb4832e22ebd355524563", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.1.1", + "phpunit/phpunit": "^4|^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Assert\\": "lib/Assert" + }, + "files": [ + "lib/Assert/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de", + "role": "Lead Developer" + }, + { + "name": "Richard Quadling", + "email": "rquadling@gmail.com", + "role": "Collaborator" + } + ], + "description": "Thin assertion library for input validation in business models.", + "keywords": [ + "assert", + "assertion", + "validation" + ], + "time": "2017-05-04 02:00:24" + }, + { + "name": "container-interop/container-interop", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/container-interop/container-interop.git", + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", + "shasum": "" + }, + "require": { + "psr/container": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Interop\\Container\\": "src/Interop/Container/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", + "homepage": "https://github.com/container-interop/container-interop", + "time": "2017-02-14 19:40:03" + }, + { + "name": "doctrine/annotations", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "5beebb01b025c94e93686b7a0ed3edae81fe3e7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/5beebb01b025c94e93686b7a0ed3edae81fe3e7f", + "reference": "5beebb01b025c94e93686b7a0ed3edae81fe3e7f", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2017-07-22 10:58:02" + }, { "name": "doctrine/instantiator", "version": "1.1.0", @@ -110,6 +311,351 @@ ], "time": "2017-07-22 11:58:36" }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, + { + "name": "lstrojny/functional-php", + "version": "1.6.0", + "source": { + "type": "git", + "url": "https://github.com/lstrojny/functional-php.git", + "reference": "c0c15f048355d0a7ab17914022ec1f901fe5144a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lstrojny/functional-php/zipball/c0c15f048355d0a7ab17914022ec1f901fe5144a", + "reference": "c0c15f048355d0a7ab17914022ec1f901fe5144a", + "shasum": "" + }, + "require": { + "php": "~7" + }, + "require-dev": { + "phpunit/phpunit": "~6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "Functional\\": "src/Functional" + }, + "files": [ + "src/Functional/Average.php", + "src/Functional/Capture.php", + "src/Functional/ConstFunction.php", + "src/Functional/CompareOn.php", + "src/Functional/CompareObjectHashOn.php", + "src/Functional/Compose.php", + "src/Functional/Concat.php", + "src/Functional/Contains.php", + "src/Functional/Curry.php", + "src/Functional/CurryN.php", + "src/Functional/Difference.php", + "src/Functional/DropFirst.php", + "src/Functional/DropLast.php", + "src/Functional/Each.php", + "src/Functional/Equal.php", + "src/Functional/ErrorToException.php", + "src/Functional/Every.php", + "src/Functional/False.php", + "src/Functional/Falsy.php", + "src/Functional/Filter.php", + "src/Functional/First.php", + "src/Functional/FirstIndexOf.php", + "src/Functional/FlatMap.php", + "src/Functional/Flatten.php", + "src/Functional/Flip.php", + "src/Functional/GreaterThan.php", + "src/Functional/GreaterThanOrEqual.php", + "src/Functional/Group.php", + "src/Functional/Head.php", + "src/Functional/Id.php", + "src/Functional/IfElse.php", + "src/Functional/Identical.php", + "src/Functional/IndexesOf.php", + "src/Functional/Intersperse.php", + "src/Functional/Invoke.php", + "src/Functional/InvokeFirst.php", + "src/Functional/InvokeIf.php", + "src/Functional/InvokeLast.php", + "src/Functional/Invoker.php", + "src/Functional/Last.php", + "src/Functional/LastIndexOf.php", + "src/Functional/LessThan.php", + "src/Functional/LessThanOrEqual.php", + "src/Functional/LexicographicCompare.php", + "src/Functional/Map.php", + "src/Functional/Match.php", + "src/Functional/Maximum.php", + "src/Functional/Memoize.php", + "src/Functional/Minimum.php", + "src/Functional/None.php", + "src/Functional/Not.php", + "src/Functional/PartialAny.php", + "src/Functional/PartialLeft.php", + "src/Functional/PartialMethod.php", + "src/Functional/PartialRight.php", + "src/Functional/Partition.php", + "src/Functional/Pick.php", + "src/Functional/Pluck.php", + "src/Functional/Poll.php", + "src/Functional/Product.php", + "src/Functional/Ratio.php", + "src/Functional/ReduceLeft.php", + "src/Functional/ReduceRight.php", + "src/Functional/Reindex.php", + "src/Functional/Reject.php", + "src/Functional/Retry.php", + "src/Functional/Select.php", + "src/Functional/SequenceConstant.php", + "src/Functional/SequenceExponential.php", + "src/Functional/SequenceLinear.php", + "src/Functional/Some.php", + "src/Functional/Sort.php", + "src/Functional/Sum.php", + "src/Functional/SuppressError.php", + "src/Functional/Tail.php", + "src/Functional/TailRecursion.php", + "src/Functional/True.php", + "src/Functional/Truthy.php", + "src/Functional/Unique.php", + "src/Functional/With.php", + "src/Functional/Zip.php", + "src/Functional/ZipAll.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Lars Strojny", + "email": "lstrojny@php.net", + "homepage": "http://usrportage.de" + }, + { + "name": "Max Beutel", + "email": "nash12@gmail.com" + } + ], + "description": "Functional primitives for PHP", + "keywords": [ + "functional" + ], + "time": "2017-05-08 10:17:44" + }, + { + "name": "phpbench/container", + "version": "1.1", + "source": { + "type": "git", + "url": "https://github.com/phpbench/container.git", + "reference": "8cd29cf58104e68b4d5cc2af5703e6235e41e7b9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpbench/container/zipball/8cd29cf58104e68b4d5cc2af5703e6235e41e7b9", + "reference": "8cd29cf58104e68b4d5cc2af5703e6235e41e7b9", + "shasum": "" + }, + "require": { + "container-interop/container-interop": "^1.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpBench\\DependencyInjection\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Leech", + "email": "daniel@dantleech.com" + } + ], + "description": "Simple, configurable, service container.", + "time": "2017-07-18 12:10:10" + }, + { + "name": "phpbench/dom", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpbench/dom.git", + "reference": "b135378dd0004c05ba5446aeddaf0b83339c1c4c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpbench/dom/zipball/b135378dd0004c05ba5446aeddaf0b83339c1c4c", + "reference": "b135378dd0004c05ba5446aeddaf0b83339c1c4c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": "^5.4|^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpBench\\Dom\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Leech", + "email": "daniel@dantleech.com" + } + ], + "description": "DOM wrapper to simplify working with the PHP DOM implementation", + "time": "2016-02-27 12:15:56" + }, + { + "name": "phpbench/phpbench", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/phpbench/phpbench.git", + "reference": "acbfdd1439bddf7de8f7f803dd819341d3c069c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpbench/phpbench/zipball/acbfdd1439bddf7de8f7f803dd819341d3c069c4", + "reference": "acbfdd1439bddf7de8f7f803dd819341d3c069c4", + "shasum": "" + }, + "require": { + "beberlei/assert": "^2.4", + "doctrine/annotations": "^1.2.7", + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "lstrojny/functional-php": "1.0|^1.2.3", + "php": "^7.0", + "phpbench/container": "~1.0", + "phpbench/dom": "~0.2.0", + "seld/jsonlint": "^1.0", + "symfony/console": "^2.6|^3.0|^4.0", + "symfony/debug": "^2.4|^3.0|^4.0", + "symfony/filesystem": "^2.4|^3.0|^4.0", + "symfony/finder": "^2.4|^3.0|^4.0", + "symfony/options-resolver": "^2.6|^3.0|^4.0", + "symfony/process": "^2.1|^3.0|^4.0" + }, + "require-dev": { + "doctrine/dbal": "^2.4", + "liip/rmt": "^1.2", + "padraic/phar-updater": "^1.0", + "phpunit/phpunit": "^6.0" + }, + "bin": [ + "bin/phpbench" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpBench\\": "lib/", + "PhpBench\\Extensions\\Dbal\\": "extensions/dbal/lib/", + "PhpBench\\Extensions\\XDebug\\": "extensions/xdebug/lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Leech", + "email": "daniel@dantleech.com" + } + ], + "description": "PHP Benchmarking Framework", + "time": "2017-09-14 09:35:17" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0", @@ -491,6 +1037,55 @@ ], "time": "2017-03-02 20:05:34" }, + { + "name": "psr/container", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-02-14 16:28:37" + }, { "name": "psr/log", "version": "1.0.2", @@ -774,6 +1369,55 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2017-03-03 06:23:57" }, + { + "name": "seld/jsonlint", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/jsonlint.git", + "reference": "50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77", + "reference": "50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77", + "shasum": "" + }, + "require": { + "php": "^5.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5" + }, + "bin": [ + "bin/jsonlint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Seld\\JsonLint\\": "src/Seld/JsonLint/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "JSON Linter", + "keywords": [ + "json", + "linter", + "parser", + "validator" + ], + "time": "2017-06-18 15:11:04" + }, { "name": "symfony/console", "version": "v3.3.6", @@ -962,6 +1606,55 @@ "homepage": "https://symfony.com", "time": "2017-06-09 14:53:08" }, + { + "name": "symfony/filesystem", + "version": "v3.3.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "b32a0e5f928d0fa3d1dd03c78d020777e50c10cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b32a0e5f928d0fa3d1dd03c78d020777e50c10cb", + "reference": "b32a0e5f928d0fa3d1dd03c78d020777e50c10cb", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2017-07-29 21:54:42" + }, { "name": "symfony/finder", "version": "v3.3.6", @@ -1011,6 +1704,60 @@ "homepage": "https://symfony.com", "time": "2017-06-01 21:01:25" }, + { + "name": "symfony/options-resolver", + "version": "v3.3.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "ee4e22978fe885b54ee5da8c7964f0a5301abfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/ee4e22978fe885b54ee5da8c7964f0a5301abfb6", + "reference": "ee4e22978fe885b54ee5da8c7964f0a5301abfb6", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony OptionsResolver Component", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "time": "2017-07-29 21:54:42" + }, { "name": "symfony/polyfill-mbstring", "version": "v1.4.0", @@ -1334,7 +2081,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "phpbench/phpbench": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/php/phpbench.json b/php/phpbench.json new file mode 100644 index 0000000..305a194 --- /dev/null +++ b/php/phpbench.json @@ -0,0 +1,5 @@ +{ + "bootstrap": "vendor/autoload.php", + "path": "src/benchmarks", + "retry_threshold": 5 +} \ No newline at end of file diff --git a/php/src/LambdaRoma/KataZero/KataZeroFP.php b/php/src/LambdaRoma/KataZero/KataZeroLaravelCollection.php similarity index 98% rename from php/src/LambdaRoma/KataZero/KataZeroFP.php rename to php/src/LambdaRoma/KataZero/KataZeroLaravelCollection.php index 989ad9d..7478da9 100644 --- a/php/src/LambdaRoma/KataZero/KataZeroFP.php +++ b/php/src/LambdaRoma/KataZero/KataZeroLaravelCollection.php @@ -8,7 +8,7 @@ * Class KataZeroFP * @package LambdaRoma\KataZero */ -class KataZeroFP +class KataZeroLaravelCollection { /** * @return Collection diff --git a/php/src/LambdaRoma/KataZero/KataZeroQaribu.php b/php/src/LambdaRoma/KataZero/KataZeroQaribu.php new file mode 100644 index 0000000..96885fe --- /dev/null +++ b/php/src/LambdaRoma/KataZero/KataZeroQaribu.php @@ -0,0 +1,147 @@ +filter(function ($i) { + return strtolower($i[0]) === 'c'; + }); + } + + public function kataZeroE(): int + { + $range = ImmArray::fromArray(range(8, 100, 8)); + $count = $range->count(); + $sum = $range->reduce(function ($item, $curry) { + return $curry + $item; + }, 0); + return $sum / $count; + } + + /** + * @return int + */ + public function kataZeroF(): int + { + $range = ImmArray::fromArray(range(6, 1000, 6)); + return $range->reduce(function ($item, $curry) { + return $curry + $item; + }, 0); + } + + /** + * @param array $menNames + * @return ImmArray + */ + public function kataZeroG(array $menNames) + { + return ImmArray::fromArray($menNames)->sort(); + } + + /** + * @return int + */ + public function kataZeroH(): int + { + $range = range(41, 1000, 41); + return $range[array_rand($range)]; + } + + /** + * @param $menNames + * @return mixed|null + */ + public function kataZeroI(array $menNames): string + { + return ImmArray::fromArray($menNames)->join(', '); + } + + /** + * @param $menNames + * @return ImmArray + */ + public function kataZeroJ(array $menNames): ImmArray + { + return ImmArray::fromArray(array_unique($menNames)); + } + + /** + * TODO REWORK + * @param array $womenNames + * @return array + */ + public function kataZeroK(array $womenNames): array + { + $immutableWN = ImmArray::fromArray($womenNames); + $ids = $immutableWN->map(function ($i) { + return strlen($i); + }); + $indexedWomenNames = ImmArray::fromArray(array_map(null, $ids->toArray(), $immutableWN->toArray())); + + return $indexedWomenNames->reduce(function ($last, $curr) { + $key = array_shift($curr); + $val = array_shift($curr); + if(isset($last[$key]) && is_array($last[$key])) { + array_push($last[$key], $val); + return $last; + } + $last[$key] = [$val]; + return $last; + }, []); + } + + /** + * @param $womenNames + * @return ImmArray + */ + public function kataZeroL(array $womenNames): ImmArray + { + return ImmArray::fromArray($womenNames)->map(function ($i) { + return strlen($i); + }); + } + + /** + * @param $womenNames + * @return ImmArray + */ + public function kataZeroM($womenNames): ImmArray + { + return ImmArray::fromArray($womenNames)->map(function ($i) { + return $i[0]; + }); + } +} diff --git a/php/src/benchmarks/LambdaRoma/KataZeroBench.php b/php/src/benchmarks/LambdaRoma/KataZeroBench.php new file mode 100644 index 0000000..5a2dd94 --- /dev/null +++ b/php/src/benchmarks/LambdaRoma/KataZeroBench.php @@ -0,0 +1,83 @@ +subject = new KataZero(); + } + + public function benchKataZeroA() + { + $this->subject->kataZeroA(); + } + + public function benchKataZeroB() + { + $this->subject->kataZeroB(); + } + + public function benchKataZeroC() + { + $this->subject->kataZeroC(); + } + + public function benchKataZeroD() + { + $this->subject->kataZeroD($this->men); + } + + public function benchKataZeroE() + { + $this->subject->kataZeroE(); + } + + public function benchKataZeroF() + { + $this->subject->kataZeroF(); + } + + public function benchKataZeroG() + { + $this->subject->kataZeroG($this->men); + } + + public function benchKataZeroI() + { + $this->subject->kataZeroI($this->men); + } + + public function benchKataZeroJ() + { + $this->subject->kataZeroJ($this->men); + } + + public function benchKataZeroK() + { + $this->subject->kataZeroK($this->women); + } + + public function benchKataZeroL() + { + $this->subject->kataZeroL($this->women); + } + + public function benchKataZeroM() + { + $this->subject->kataZeroM($this->women); + } +} \ No newline at end of file diff --git a/php/src/benchmarks/LambdaRoma/KataZeroLaravelCollectionBench.php b/php/src/benchmarks/LambdaRoma/KataZeroLaravelCollectionBench.php new file mode 100644 index 0000000..3f8cb38 --- /dev/null +++ b/php/src/benchmarks/LambdaRoma/KataZeroLaravelCollectionBench.php @@ -0,0 +1,83 @@ +subject = new KataZeroLaravelCollection(); + } + + public function benchKataZeroA() + { + $this->subject->kataZeroA(); + } + + public function benchKataZeroB() + { + $this->subject->kataZeroB(); + } + + public function benchKataZeroC() + { + $this->subject->kataZeroC(); + } + + public function benchKataZeroD() + { + $this->subject->kataZeroD($this->men); + } + + public function benchKataZeroE() + { + $this->subject->kataZeroE(); + } + + public function benchKataZeroF() + { + $this->subject->kataZeroF(); + } + + public function benchKataZeroG() + { + $this->subject->kataZeroG($this->men); + } + + public function benchKataZeroI() + { + $this->subject->kataZeroI($this->men); + } + + public function benchKataZeroJ() + { + $this->subject->kataZeroJ($this->men); + } + + public function benchKataZeroK() + { + $this->subject->kataZeroK($this->women); + } + + public function benchKataZeroL() + { + $this->subject->kataZeroL($this->women); + } + + public function benchKataZeroM() + { + $this->subject->kataZeroM($this->women); + } +} \ No newline at end of file diff --git a/php/src/benchmarks/LambdaRoma/KataZeroQaribuBench.php b/php/src/benchmarks/LambdaRoma/KataZeroQaribuBench.php new file mode 100644 index 0000000..9fc01b8 --- /dev/null +++ b/php/src/benchmarks/LambdaRoma/KataZeroQaribuBench.php @@ -0,0 +1,83 @@ +subject = new KataZeroQaribu(); + } + + public function benchKataZeroA() + { + $this->subject->kataZeroA(); + } + + public function benchKataZeroB() + { + $this->subject->kataZeroB(); + } + + public function benchKataZeroC() + { + $this->subject->kataZeroC(); + } + + public function benchKataZeroD() + { + $this->subject->kataZeroD($this->men); + } + + public function benchKataZeroE() + { + $this->subject->kataZeroE(); + } + + public function benchKataZeroF() + { + $this->subject->kataZeroF(); + } + + public function benchKataZeroG() + { + $this->subject->kataZeroG($this->men); + } + + public function benchKataZeroI() + { + $this->subject->kataZeroI($this->men); + } + + public function benchKataZeroJ() + { + $this->subject->kataZeroJ($this->men); + } + + public function benchKataZeroK() + { + $this->subject->kataZeroK($this->women); + } + + public function benchKataZeroL() + { + $this->subject->kataZeroL($this->women); + } + + public function benchKataZeroM() + { + $this->subject->kataZeroM($this->women); + } +} \ No newline at end of file diff --git a/php/src/spec/LambdaRoma/KataZero/KataZeroFPSpec.php b/php/src/spec/LambdaRoma/KataZero/KataZeroLaravelCollectionSpec.php similarity index 93% rename from php/src/spec/LambdaRoma/KataZero/KataZeroFPSpec.php rename to php/src/spec/LambdaRoma/KataZero/KataZeroLaravelCollectionSpec.php index f3483c3..8525bbd 100644 --- a/php/src/spec/LambdaRoma/KataZero/KataZeroFPSpec.php +++ b/php/src/spec/LambdaRoma/KataZero/KataZeroLaravelCollectionSpec.php @@ -2,18 +2,18 @@ namespace spec\LambdaRoma\KataZero; -use LambdaRoma\KataZero\KataZeroFP; +use LambdaRoma\KataZero\KataZeroLaravelCollection; use PhpSpec\ObjectBehavior; use Prophecy\Argument; -class KataZeroFPSpec extends ObjectBehavior +class KataZeroLaravelCollectionSpec extends ObjectBehavior { private $men = ["Tizio", "Caio", "Sempronio", "Mevio", "Filano", "Calpurnio"]; private $women = ["Anna", "Carla", "Angela", "Chiara", "Emma", "Maria", "Sara"]; function it_is_initializable() { - $this->shouldHaveType(KataZeroFP::class); + $this->shouldHaveType(KataZeroLaravelCollection::class); } function it_should_return_123() diff --git a/php/src/spec/LambdaRoma/KataZero/KataZeroQaribuSpec.php b/php/src/spec/LambdaRoma/KataZero/KataZeroQaribuSpec.php new file mode 100644 index 0000000..fe1923c --- /dev/null +++ b/php/src/spec/LambdaRoma/KataZero/KataZeroQaribuSpec.php @@ -0,0 +1,98 @@ +shouldHaveType(KataZeroQaribu::class); + } + + function it_should_return_123() + { + $this->kataZeroA()->toArray()->shouldBe([1, 2, 3]); + } + + function it_should_return_even_numbers() + { + $this->kataZeroB()->toArray()->shouldBe([0, 2, 4, 6, 8, 10]); + } + + function it_should_find_seven_multiple() + { + $this->kataZeroC()->toArray()->shouldBe([7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98]); + } + + function it_should_return_c_names() + { + $this->kataZeroD($this->men)->toArray()->shouldBe(['Caio', 'Calpurnio']); + } + + function it_should_return_average_of_eight_multiples() + { + $this->kataZeroE()->shouldBe(52); + } + + function it_should_return_sum_of_six_multiples() + { + $this->kataZeroF()->shouldBe(83166); + } + + function it_should_order_men_names() + { + $this->kataZeroG($this->men) + ->toArray() + ->shouldBe(['Caio', 'Calpurnio', 'Filano', 'Mevio', 'Sempronio', 'Tizio']); + } + + function it_should_find_a_number_divisible_by_41() + { + $this->kataZeroH()->shouldBeMultipleOf41(); + } + + function it_should_return_a_string_with_men_names() + { + $this->kataZeroI($this->men)->shouldBe("Tizio, Caio, Sempronio, Mevio, Filano, Calpurnio"); + } + + function it_should_return_a_set_of_men_names() + { + $this->kataZeroJ($this->men)->toArray()->shouldBe($this->men); + } + + function it_should_return_a_map_of_ordered_women_names() + { + $this->kataZeroK($this->women)->shouldBe([ + 4 => ["Anna", "Emma", "Sara"], + 5 => ["Carla", "Maria"], + 6 => ["Angela", "Chiara"] + ]); + } + + function it_should_return_list_of_lengths_of_women_names() + { + $this->kataZeroL($this->women)->toArray()->shouldBe([4, 5, 6, 6, 4, 5, 4]); + } + + function it_should_return_list_of_womens_initials() + { + $this->kataZeroM($this->women)->toArray()->shouldBe(['A', 'C', 'A', 'C', 'E', 'M', 'S']); + } + + function getMatchers() + { + return [ + 'beMultipleOf41' => function ($subject) { + return $subject % 41 === 0; + } + ]; + } +}