From fe1213ec13547b6eae179caf42aad2a73aea8594 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Thu, 8 Dec 2022 21:17:08 +0300 Subject: [PATCH 01/16] added console command --- README.MD | 3 +- composer.json | 3 + composer.lock | 722 +++++++++++++++++- console.php | 12 + .../Console/Commands/SolveEquationCommand.php | 33 + 5 files changed, 770 insertions(+), 3 deletions(-) create mode 100644 console.php create mode 100644 src/Infrastructure/Console/Commands/SolveEquationCommand.php diff --git a/README.MD b/README.MD index 060c407..7b95272 100644 --- a/README.MD +++ b/README.MD @@ -1,2 +1,3 @@ - Чтобы развернуть проект локально, можно использовать ``docker-compose up`` внутри директории docker -- Чтобы запустить автотесты, необходимо выполнить команду ``./vendor/bin/phpunit tests`` \ No newline at end of file +- Чтобы запустить автотесты, необходимо выполнить команду ``./vendor/bin/phpunit tests`` +- Чтобы выполнить консольную команду решения уравнения, необходимо выполнить ``php console.php app:solve-equation`` \ No newline at end of file diff --git a/composer.json b/composer.json index 977d51e..d8fe62f 100644 --- a/composer.json +++ b/composer.json @@ -13,5 +13,8 @@ "require-dev": { "phpunit/phpunit": "^9.5", "mockery/mockery": "^1.5" + }, + "require": { + "symfony/console": "^6.2" } } diff --git a/composer.lock b/composer.lock index b80ae2d..1f59108 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,726 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1e0f59c10f4892f0cf866629d4e71768", - "packages": [], + "content-hash": "21299afe01fea421b40b84af0e9a5b89", + "packages": [ + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://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" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" + }, + { + "name": "symfony/console", + "version": "v6.2.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "58f6cef5dc5f641b7bbdbf8b32b44cc926c35f3f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/58f6cef5dc5f641b7bbdbf8b32b44cc926c35f3f", + "reference": "58f6cef5dc5f641b7bbdbf8b32b44cc926c35f3f", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-mbstring": "~1.0", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/string": "^5.4|^6.0" + }, + "conflict": { + "symfony/dependency-injection": "<5.4", + "symfony/dotenv": "<5.4", + "symfony/event-dispatcher": "<5.4", + "symfony/lock": "<5.4", + "symfony/process": "<5.4" + }, + "provide": { + "psr/log-implementation": "1.0|2.0|3.0" + }, + "require-dev": { + "psr/log": "^1|^2|^3", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/lock": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "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": "Eases the creation of beautiful and testable command line interfaces", + "homepage": "https://symfony.com", + "keywords": [ + "cli", + "command line", + "console", + "terminal" + ], + "support": { + "source": "https://github.com/symfony/console/tree/v6.2.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-12-01T13:44:20+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "1ee04c65529dea5d8744774d474e7cbd2f1206d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/1ee04c65529dea5d8744774d474e7cbd2f1206d3", + "reference": "1ee04c65529dea5d8744774d474e7cbd2f1206d3", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.3-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-25T10:21:52+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-intl-grapheme", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-grapheme.git", + "reference": "511a08c03c1960e08a883f4cffcacd219b758354" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354", + "reference": "511a08c03c1960e08a883f4cffcacd219b758354", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's grapheme_* functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "grapheme", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/service-contracts", + "version": "v3.1.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/service-contracts.git", + "reference": "925e713fe8fcacf6bc05e936edd8dd5441a21239" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/925e713fe8fcacf6bc05e936edd8dd5441a21239", + "reference": "925e713fe8fcacf6bc05e936edd8dd5441a21239", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "psr/container": "^2.0" + }, + "conflict": { + "ext-psr": "<1.1|>=2" + }, + "suggest": { + "symfony/service-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.1-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Service\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to writing services", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/service-contracts/tree/v3.1.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-30T19:18:58+00:00" + }, + { + "name": "symfony/string", + "version": "v6.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/string.git", + "reference": "145702685e0d12f81d755c71127bfff7582fdd36" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/string/zipball/145702685e0d12f81d755c71127bfff7582fdd36", + "reference": "145702685e0d12f81d755c71127bfff7582fdd36", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-normalizer": "~1.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/translation-contracts": "<2.0" + }, + "require-dev": { + "symfony/error-handler": "^5.4|^6.0", + "symfony/http-client": "^5.4|^6.0", + "symfony/intl": "^6.2", + "symfony/translation-contracts": "^2.0|^3.0", + "symfony/var-exporter": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/functions.php" + ], + "psr-4": { + "Symfony\\Component\\String\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", + "homepage": "https://symfony.com", + "keywords": [ + "grapheme", + "i18n", + "string", + "unicode", + "utf-8", + "utf8" + ], + "support": { + "source": "https://github.com/symfony/string/tree/v6.2.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-30T17:13:47+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", diff --git a/console.php b/console.php new file mode 100644 index 0000000..d9c8c5d --- /dev/null +++ b/console.php @@ -0,0 +1,12 @@ +add(new SolveEquationCommand()); + +$application->run(); diff --git a/src/Infrastructure/Console/Commands/SolveEquationCommand.php b/src/Infrastructure/Console/Commands/SolveEquationCommand.php new file mode 100644 index 0000000..cd0c91d --- /dev/null +++ b/src/Infrastructure/Console/Commands/SolveEquationCommand.php @@ -0,0 +1,33 @@ + Date: Sun, 11 Dec 2022 20:50:05 +0300 Subject: [PATCH 02/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=B2=D0=B0=D0=B4?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=83=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 3 +- src/AppBundle/Domains/EquationManager.php | 48 ++++++++++++ .../Console/Commands/SolveEquationCommand.php | 78 +++++++++++++++---- tests/Unit/SolveTest.php | 34 +++++++- 4 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 src/AppBundle/Domains/EquationManager.php diff --git a/README.MD b/README.MD index 7b95272..4b12d0d 100644 --- a/README.MD +++ b/README.MD @@ -1,3 +1,4 @@ - Чтобы развернуть проект локально, можно использовать ``docker-compose up`` внутри директории docker - Чтобы запустить автотесты, необходимо выполнить команду ``./vendor/bin/phpunit tests`` -- Чтобы выполнить консольную команду решения уравнения, необходимо выполнить ``php console.php app:solve-equation`` \ No newline at end of file +- Чтобы выполнить консольную команду решения уравнения, необходимо выполнить ``php console.php app:solve-equation`` +- Пример команды c параметрами: ``php console.php app:solve-equation '-5.765' 1 '-3.23`` \ No newline at end of file diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php new file mode 100644 index 0000000..65593b9 --- /dev/null +++ b/src/AppBundle/Domains/EquationManager.php @@ -0,0 +1,48 @@ + 0) { + $x1 = (-$b + sqrt($discriminant)) / 2 * $a; + $x2 = (-$b - sqrt($discriminant)) / 2 * $a; + } elseif (self::CompareWithZero($discriminant, 0)) { + $x1 = $x2 = (-$b) / 2 * $a; + } else { + return []; + } + + return [(float)$x1, (float)$x2]; + } + + /** + * Сравнивает числа с плавающей точкой с нулём + * + * @param float $a + * + * @return bool + */ + private static function CompareWithZero(float $a): bool + { + return abs($a) < PHP_FLOAT_EPSILON; + } +} diff --git a/src/Infrastructure/Console/Commands/SolveEquationCommand.php b/src/Infrastructure/Console/Commands/SolveEquationCommand.php index cd0c91d..bc60358 100644 --- a/src/Infrastructure/Console/Commands/SolveEquationCommand.php +++ b/src/Infrastructure/Console/Commands/SolveEquationCommand.php @@ -1,33 +1,83 @@ addArgument('a', InputArgument::OPTIONAL, 'Значение а') + ->addArgument('b', InputArgument::OPTIONAL, 'Значение b') + ->addArgument('c', InputArgument::OPTIONAL, 'Значение c'); + } + protected function execute(InputInterface $input, OutputInterface $output): int { - // ... put here the code to create the user + $a = $input->getArgument('a'); + $b = $input->getArgument('b'); + $c = $input->getArgument('c'); - // this method must return an integer number with the "exit status code" - // of the command. You can also use these constants to make code more readable + $output->writeln([ + 'Решение квадратного уравнения', + '============', + '', + ]); - // return this if there was no problem running the command - // (it's equivalent to returning int(0)) - return Command::SUCCESS; + $a = $this->inputFormatter($a); + $b = $this->inputFormatter($b); + $c = $this->inputFormatter($c); - // or return this if some error happened during the execution - // (it's equivalent to returning int(1)) - // return Command::FAILURE; + $equation = new EquationManager(); + $value = $equation::solve($a, $b, $c); - // or return this to indicate incorrect command usage; e.g. invalid options - // or missing arguments (it's equivalent to returning int(2)) - // return Command::INVALID + if ($value === null) { + $output->write('Не передан обязательный аттрибут \'a\''); + return Command::FAILURE; + } + + if ($value === []) { + $output->write('Корней нет'); + return Command::SUCCESS; + } + [$x1, $x2] = $value; + + $output->writeln([ + 'Корни квадратного уравнения:', + 'x1=' . $x1, + 'x2=' . $x2, + ]); + + return Command::SUCCESS; + } + + /** + * Форматирует входные данные + * @FIXME найти способ лучше (проблема в том, что символ "-" консоль воспринимает как название параметра, + * поэтому отрицательные числа приходится передавать в '' + * + * @param string|null $value + * @return float|null + */ + private function inputFormatter(string|null $value): ?float + { + if ($value === null) { + return null; + } + $value = str_replace("'", "", $value); + return (float)$value; } -} \ No newline at end of file +} diff --git a/tests/Unit/SolveTest.php b/tests/Unit/SolveTest.php index ca740a2..171db94 100644 --- a/tests/Unit/SolveTest.php +++ b/tests/Unit/SolveTest.php @@ -2,12 +2,44 @@ namespace Tests\Unit; +use App\AppBundle\Domains\EquationManager; use PHPUnit\Framework\TestCase; class SolveTest extends TestCase { + private EquationManager $equation; + + public function __construct(?string $name = null, array $data = [], $dataName = '') + { + $this->equation = new EquationManager(); + parent::__construct($name, $data, $dataName); + } + public function testHaveNotRoots() { - $this->assertSame(true, true); + // x^2+1 = 0 + $value = $this->equation::solve(1, 0, 1); + $this->assertSame([], $value); + } + + public function testHaveTwoRoots() + { + // x^2-1 = 0 + $value = $this->equation::solve(1, 0, -1); + $this->assertEquals([1, -1], $value); + } + + public function testHaveOneRoot() + { + // x^2+2x+1 + $value = $this->equation::solve(1, 2, 1); + $this->assertEquals([-1, -1], $value); + } + + public function testIsNull() + { + // a=0 + $value = $this->equation::solve(0); + $this->assertNull($value); } } \ No newline at end of file From 5fef56233e97c6db8dd03e12ae1e4c7a6e7196ba Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Mon, 12 Dec 2022 23:01:32 +0300 Subject: [PATCH 03/16] added travis config --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..046f8d8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: php + +php: + - 8.1 + +before_script: + - composer --dev install + +script: ./vendor/bin/phpunit tests \ No newline at end of file From 5d171ce91cffb4ec1d0fe279d29d2cca9ca26d42 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Mon, 12 Dec 2022 23:06:21 +0300 Subject: [PATCH 04/16] added travis config --- README.MD | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.MD b/README.MD index 4b12d0d..76c7763 100644 --- a/README.MD +++ b/README.MD @@ -1,4 +1,5 @@ - Чтобы развернуть проект локально, можно использовать ``docker-compose up`` внутри директории docker - Чтобы запустить автотесты, необходимо выполнить команду ``./vendor/bin/phpunit tests`` - Чтобы выполнить консольную команду решения уравнения, необходимо выполнить ``php console.php app:solve-equation`` -- Пример команды c параметрами: ``php console.php app:solve-equation '-5.765' 1 '-3.23`` \ No newline at end of file +- Пример команды c параметрами: ``php console.php app:solve-equation '-5.765' 1 '-3.23`` + [![Build Status](https://app.travis-ci.com/MercerMorning/main_patterns_2022_php.svg?branch=master)](https://app.travis-ci.com/MercerMorning/main_patterns_2022_php) \ No newline at end of file From 0bcd64257302fd0aaeb7ac4fdb2fe409edcf30a9 Mon Sep 17 00:00:00 2001 From: Nikolay Vasilev <48645940+MercerMorning@users.noreply.github.com> Date: Mon, 12 Dec 2022 23:14:08 +0300 Subject: [PATCH 05/16] Create php.yml --- .github/workflows/php.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..a7d195f --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,39 @@ +name: PHP Composer + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" + # Docs: https://getcomposer.org/doc/articles/scripts.md + + # - name: Run test suite + # run: composer run-script test From fba722752f4560dc6d309b21af04a27673d19577 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Mon, 12 Dec 2022 23:14:44 +0300 Subject: [PATCH 06/16] Revert "added travis config" This reverts commit 5d171ce91cffb4ec1d0fe279d29d2cca9ca26d42. --- README.MD | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.MD b/README.MD index 76c7763..4b12d0d 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,4 @@ - Чтобы развернуть проект локально, можно использовать ``docker-compose up`` внутри директории docker - Чтобы запустить автотесты, необходимо выполнить команду ``./vendor/bin/phpunit tests`` - Чтобы выполнить консольную команду решения уравнения, необходимо выполнить ``php console.php app:solve-equation`` -- Пример команды c параметрами: ``php console.php app:solve-equation '-5.765' 1 '-3.23`` - [![Build Status](https://app.travis-ci.com/MercerMorning/main_patterns_2022_php.svg?branch=master)](https://app.travis-ci.com/MercerMorning/main_patterns_2022_php) \ No newline at end of file +- Пример команды c параметрами: ``php console.php app:solve-equation '-5.765' 1 '-3.23`` \ No newline at end of file From 82c57661beea1f752dce90bf8f45d47af2dad89c Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Mon, 12 Dec 2022 23:14:44 +0300 Subject: [PATCH 07/16] Revert "added travis config" This reverts commit 5fef56233e97c6db8dd03e12ae1e4c7a6e7196ba. --- .travis.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 046f8d8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: php - -php: - - 8.1 - -before_script: - - composer --dev install - -script: ./vendor/bin/phpunit tests \ No newline at end of file From 685369c7ee7349581fa680c13c54c30e8ee66333 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Mon, 12 Dec 2022 23:22:14 +0300 Subject: [PATCH 08/16] change ci --- .github/workflows/php.yml | 36 +++++++----------------------------- composer.json | 3 +++ 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a7d195f..272ae14 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,13 +1,6 @@ -name: PHP Composer +name: Github Actions for PHP with PHPUnit Tests -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -permissions: - contents: read +on: [push] jobs: build: @@ -15,25 +8,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v3 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - - name: Install dependencies - run: composer install --prefer-dist --no-progress + - uses: actions/checkout@v3 - # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" - # Docs: https://getcomposer.org/doc/articles/scripts.md + - name: Install dependencies + run: composer --dev install - # - name: Run test suite - # run: composer run-script test + - name: Run test suite + run: composer run-script test \ No newline at end of file diff --git a/composer.json b/composer.json index d8fe62f..7620776 100644 --- a/composer.json +++ b/composer.json @@ -16,5 +16,8 @@ }, "require": { "symfony/console": "^6.2" + }, + "scripts": { + "test": "./vendor/bin/phpunit tests" } } From ededcea103c9c5e2e1cb4ee22716010ce422c020 Mon Sep 17 00:00:00 2001 From: "andrey.b" Date: Tue, 13 Dec 2022 20:06:19 +0300 Subject: [PATCH 09/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Исправляет метод сравнения с нулём - Добавляет выброс исключения при а = 0 - Добавляет новое исключение для равества нулю числа с плавающей точкой --- src/AppBundle/Domains/EquationManager.php | 19 +++++++++++-------- .../Exceptions/EqualsZeroException.php | 8 ++++++++ .../Console/Commands/SolveEquationCommand.php | 8 ++++---- tests/Unit/SolveTest.php | 5 +++-- 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/AppBundle/Domains/Exceptions/EqualsZeroException.php diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index 65593b9..7174c53 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -4,6 +4,8 @@ namespace App\AppBundle\Domains; +use App\AppBundle\Domains\Exceptions\EqualsZeroException; + class EquationManager { /** @@ -13,19 +15,20 @@ class EquationManager * @param float|null $b * @param float|null $c * - * @return array|null + * @return array + * @throws EqualsZeroException */ - public static function solve(?float $a, ?float $b = 0, ?float $c = 0): ?array + public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array { - if (self::CompareWithZero($a)) { - return null; + if (self::CheckLessThanZero($a)) { + throw new EqualsZeroException('Значение \'a\' не может быть равен нулю'); } $discriminant = $b * $b - 4 * $a * $c; if ($discriminant > 0) { $x1 = (-$b + sqrt($discriminant)) / 2 * $a; $x2 = (-$b - sqrt($discriminant)) / 2 * $a; - } elseif (self::CompareWithZero($discriminant, 0)) { + } elseif (self::CheckLessThanZero($discriminant)) { $x1 = $x2 = (-$b) / 2 * $a; } else { return []; @@ -37,12 +40,12 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): ?array /** * Сравнивает числа с плавающей точкой с нулём * - * @param float $a + * @param float $num * * @return bool */ - private static function CompareWithZero(float $a): bool + private static function CheckLessThanZero(float $num): bool { - return abs($a) < PHP_FLOAT_EPSILON; + return abs($num) < PHP_FLOAT_EPSILON && abs($num) >= 0; } } diff --git a/src/AppBundle/Domains/Exceptions/EqualsZeroException.php b/src/AppBundle/Domains/Exceptions/EqualsZeroException.php new file mode 100644 index 0000000..c9eaafe --- /dev/null +++ b/src/AppBundle/Domains/Exceptions/EqualsZeroException.php @@ -0,0 +1,8 @@ +inputFormatter($c); $equation = new EquationManager(); - $value = $equation::solve($a, $b, $c); - - if ($value === null) { - $output->write('Не передан обязательный аттрибут \'a\''); + try { + $value = $equation::solve($a, $b, $c); + } catch (\Exception $e) { + $output->write($e->getMessage()); return Command::FAILURE; } diff --git a/tests/Unit/SolveTest.php b/tests/Unit/SolveTest.php index 171db94..fe250d2 100644 --- a/tests/Unit/SolveTest.php +++ b/tests/Unit/SolveTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit; use App\AppBundle\Domains\EquationManager; +use App\AppBundle\Domains\Exceptions\EqualsZeroException; use PHPUnit\Framework\TestCase; class SolveTest extends TestCase @@ -38,8 +39,8 @@ public function testHaveOneRoot() public function testIsNull() { + $this->expectException(EqualsZeroException::class); // a=0 - $value = $this->equation::solve(0); - $this->assertNull($value); + $this->equation::solve(0); } } \ No newline at end of file From 7882bc1684dadbab5dc923d4324a1f30c325a5aa Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Tue, 13 Dec 2022 22:29:10 +0300 Subject: [PATCH 10/16] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=2011=D0=B9=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 4 ++-- tests/Unit/SolveTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index 7174c53..4b76289 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -26,8 +26,8 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array $discriminant = $b * $b - 4 * $a * $c; if ($discriminant > 0) { - $x1 = (-$b + sqrt($discriminant)) / 2 * $a; - $x2 = (-$b - sqrt($discriminant)) / 2 * $a; + $x1 = (-$b + sqrt($discriminant)) / (2 * $a); + $x2 = (-$b - sqrt($discriminant)) / (2 * $a); } elseif (self::CheckLessThanZero($discriminant)) { $x1 = $x2 = (-$b) / 2 * $a; } else { diff --git a/tests/Unit/SolveTest.php b/tests/Unit/SolveTest.php index fe250d2..19be963 100644 --- a/tests/Unit/SolveTest.php +++ b/tests/Unit/SolveTest.php @@ -33,8 +33,8 @@ public function testHaveTwoRoots() public function testHaveOneRoot() { // x^2+2x+1 - $value = $this->equation::solve(1, 2, 1); - $this->assertEquals([-1, -1], $value); + $value = $this->equation::solve(0.05, 0.7, -1.8); + $this->assertEquals([2.219544457292888, -16.219544457292887], $value); } public function testIsNull() From fdbfcf2f83bf14485b1186ca39d6edcef8359458 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Wed, 14 Dec 2022 00:00:58 +0300 Subject: [PATCH 11/16] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=2013=D0=B9=20=D0=BF=D1=83=D0=BD=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/SolveTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Unit/SolveTest.php b/tests/Unit/SolveTest.php index 19be963..b203cee 100644 --- a/tests/Unit/SolveTest.php +++ b/tests/Unit/SolveTest.php @@ -43,4 +43,34 @@ public function testIsNull() // a=0 $this->equation::solve(0); } + + /** + * @dataProvider otherTypesProvider + */ + public function testWithOtherTypes($arguments, $result) + { + $value = $this->equation::solve($arguments['a'], $arguments['b'], $arguments['c']); + $this->assertEquals($result, $value); + } + + private function otherTypesProvider() + { + return [ + ['arguments' => [ + 'a' => '1', + 'b' => '0', + 'c' => '1' + ], 'result' => []], + ['arguments' => [ + 'a'=>'1', + 'b' => '0', + 'c' => '-1' + ], 'result' => [1, -1]], + ['arguments' => [ + 'a' => '0.05', + 'b' => '0.7', + 'c' => '-1.8' + ], 'result' => [2.219544457292888, -16.219544457292887]], + ]; + } } \ No newline at end of file From 1d8f53c04e0978f40ea1d3315ad1a90e5de157f7 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Sun, 18 Dec 2022 10:58:31 +0300 Subject: [PATCH 12/16] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20$discriminant=20=D1=81=200,=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=20eps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index 4b76289..dedbe09 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -25,7 +25,7 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array } $discriminant = $b * $b - 4 * $a * $c; - if ($discriminant > 0) { + if (self::CheckMoreThanZero($discriminant)) { $x1 = (-$b + sqrt($discriminant)) / (2 * $a); $x2 = (-$b - sqrt($discriminant)) / (2 * $a); } elseif (self::CheckLessThanZero($discriminant)) { @@ -48,4 +48,16 @@ private static function CheckLessThanZero(float $num): bool { return abs($num) < PHP_FLOAT_EPSILON && abs($num) >= 0; } + + /** + * Проверяет что число с плавающей точкой больше нуля + * + * @param float $num + * + * @return bool + */ + private static function CheckMoreThanZero(float $num): bool + { + return abs($num) > PHP_FLOAT_EPSILON; + } } From 9802f605eec923ea8be2b504627e9122fcfec645 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Sun, 18 Dec 2022 11:10:16 +0300 Subject: [PATCH 13/16] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8E=20=D1=87?= =?UTF-8?q?=D0=B8=D1=81=D0=BB=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=81=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=20eps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index dedbe09..0774ee6 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -46,7 +46,7 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array */ private static function CheckLessThanZero(float $num): bool { - return abs($num) < PHP_FLOAT_EPSILON && abs($num) >= 0; + return $num < PHP_FLOAT_EPSILON && $num >= 0; } /** @@ -58,6 +58,6 @@ private static function CheckLessThanZero(float $num): bool */ private static function CheckMoreThanZero(float $num): bool { - return abs($num) > PHP_FLOAT_EPSILON; + return $num > PHP_FLOAT_EPSILON; } } From 8e2b97a3f821f85703acf54ced9f60fdf917cef1 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Sun, 18 Dec 2022 12:20:59 +0300 Subject: [PATCH 14/16] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=82=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8E=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B5?= =?UTF-8?q?=20check=20less=20than=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index 0774ee6..816a5f0 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -46,7 +46,7 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array */ private static function CheckLessThanZero(float $num): bool { - return $num < PHP_FLOAT_EPSILON && $num >= 0; + return abs($num) < PHP_FLOAT_EPSILON && $num >= 0; } /** From 05a5124a9b4a26b0310f5388cdf45e0d6bd409e0 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Sun, 18 Dec 2022 12:37:00 +0300 Subject: [PATCH 15/16] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=82=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8E=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B5?= =?UTF-8?q?=20check=20less=20than=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index 816a5f0..e5a7856 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -46,7 +46,7 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array */ private static function CheckLessThanZero(float $num): bool { - return abs($num) < PHP_FLOAT_EPSILON && $num >= 0; + return abs($num) < PHP_FLOAT_EPSILON && abs($num) >= 0; } /** From 47690825812055933dceb35adc14ce4ec90dbfd3 Mon Sep 17 00:00:00 2001 From: "ni.vasilev" Date: Sun, 18 Dec 2022 12:43:24 +0300 Subject: [PATCH 16/16] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=B8=D1=88=D0=BD=D1=8F=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20=D0=B2=20CheckLessThanZe?= =?UTF-8?q?ro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppBundle/Domains/EquationManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AppBundle/Domains/EquationManager.php b/src/AppBundle/Domains/EquationManager.php index e5a7856..29449db 100644 --- a/src/AppBundle/Domains/EquationManager.php +++ b/src/AppBundle/Domains/EquationManager.php @@ -46,7 +46,7 @@ public static function solve(?float $a, ?float $b = 0, ?float $c = 0): array */ private static function CheckLessThanZero(float $num): bool { - return abs($num) < PHP_FLOAT_EPSILON && abs($num) >= 0; + return abs($num) < PHP_FLOAT_EPSILON; } /**