From e0eb2d958670a873139418ef65930a12f0692623 Mon Sep 17 00:00:00 2001 From: "Making GitHub Delicious." Date: Tue, 29 Sep 2015 06:42:26 -0600 Subject: add waffle.io badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ea6d31b..8c611b8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Stories in Ready](https://badge.waffle.io/NeonXP/MathExecutor.png?label=ready&title=Ready)](https://waffle.io/NeonXP/MathExecutor) # MathExecutor [![Build Status](https://travis-ci.org/NeonXP/MathExecutor.png?branch=master)](https://travis-ci.org/NeonXP/MathExecutor) -- cgit v1.2.3 From 5d19d0660c395cf500c01c9f3f1e451f6914080b Mon Sep 17 00:00:00 2001 From: bajb Date: Fri, 1 Apr 2016 14:29:41 +0100 Subject: Avoid division by zero --- src/NXP/Classes/Token/TokenDivision.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NXP/Classes/Token/TokenDivision.php b/src/NXP/Classes/Token/TokenDivision.php index 479a4ec..7e55640 100644 --- a/src/NXP/Classes/Token/TokenDivision.php +++ b/src/NXP/Classes/Token/TokenDivision.php @@ -47,7 +47,7 @@ class TokenDivision extends AbstractOperator { $op2 = array_pop($stack); $op1 = array_pop($stack); - $result = $op1->getValue() / $op2->getValue(); + $result = $op2->getValue() > 0 ? $op1->getValue() / $op2->getValue() : 0; return new TokenNumber($result); } -- cgit v1.2.3 From 9acdc3bb5736f876c69dec51380580a4aadef201 Mon Sep 17 00:00:00 2001 From: bajb Date: Fri, 1 Apr 2016 14:52:34 +0100 Subject: Specifically check for 0 in division to allow for negative operations --- src/NXP/Classes/Token/TokenDivision.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NXP/Classes/Token/TokenDivision.php b/src/NXP/Classes/Token/TokenDivision.php index 7e55640..f1c35ff 100644 --- a/src/NXP/Classes/Token/TokenDivision.php +++ b/src/NXP/Classes/Token/TokenDivision.php @@ -47,7 +47,7 @@ class TokenDivision extends AbstractOperator { $op2 = array_pop($stack); $op1 = array_pop($stack); - $result = $op2->getValue() > 0 ? $op1->getValue() / $op2->getValue() : 0; + $result = $op2->getValue() != 0 ? $op1->getValue() / $op2->getValue() : 0; return new TokenNumber($result); } -- cgit v1.2.3 From fa935b0af637fbda34454aa679c69eaaaba1308d Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 1 Apr 2016 17:24:34 +0300 Subject: + Test for division by zero --- tests/MathTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/MathTest.php b/tests/MathTest.php index 1b96ee2..f8a271e 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -27,6 +27,12 @@ class MathTest extends \PHPUnit_Framework_TestCase $this->assertEquals($calculator->execute($expression), $phpResult); } + public function testZeroDevision() + { + $calculator = new MathExecutor(); + $this->assertEquals($calculator->execute('1 / 0'), 0); + } + /** * Expressions data provider */ @@ -62,4 +68,4 @@ class MathTest extends \PHPUnit_Framework_TestCase array('100500 * 3.5E-5') ); } -} \ No newline at end of file +} -- cgit v1.2.3 From 9e0c01722f8daf63cb1ceb77a0f0e729d2096362 Mon Sep 17 00:00:00 2001 From: charles VILLETTE Date: Thu, 7 Jul 2016 14:36:01 +0200 Subject: Removing the numeric test on setVar. --- src/NXP/MathExecutor.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 7eaa914..5cb4bca 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -91,10 +91,6 @@ class MathExecutor */ public function setVar($variable, $value) { - if (!is_numeric($value)) { - throw new \Exception("Variable value must be a number"); - } - $this->variables[$variable] = $value; return $this; -- cgit v1.2.3 From 3436e0a51ff4c709226178f897e053c0fae8da4c Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 10 Mar 2017 15:29:42 +0300 Subject: Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 586ad96..a32dc52 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "minimum-stability": "stable", "keywords": ["math","parser","expression","calculator"], "homepage": "http://github.com/NeonXP/MathExecutor", - "license": "GPLv2", + "license": "MIT", "authors": [ { "name": "Alexander 'NeonXP' Kiryukhin", -- cgit v1.2.3 From 1086fccc92e0800c873baf69fc3256008b883691 Mon Sep 17 00:00:00 2001 From: ochi51 Date: Tue, 12 Sep 2017 20:47:22 +0900 Subject: Bug fixes about "Undefined offset -1" if stack is empty array and token association is RIGHT_ASSOC --- src/NXP/Classes/Lexer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NXP/Classes/Lexer.php b/src/NXP/Classes/Lexer.php index b66ea87..e541732 100644 --- a/src/NXP/Classes/Lexer.php +++ b/src/NXP/Classes/Lexer.php @@ -99,13 +99,13 @@ class Lexer while ( count($stack) > 0 && ($stack[count($stack)-1] instanceof InterfaceOperator) && - ( + (( $token->getAssociation() == AbstractOperator::LEFT_ASSOC && $token->getPriority() <= $stack[count($stack)-1]->getPriority() ) || ( $token->getAssociation() == AbstractOperator::RIGHT_ASSOC && $token->getPriority() < $stack[count($stack)-1]->getPriority() - ) + )) ) { $output[] = array_pop($stack); } -- cgit v1.2.3 From 8d602b30dd9bf9e1b926c0d732c2ff3fe7b6644a Mon Sep 17 00:00:00 2001 From: ochi51 Date: Tue, 12 Sep 2017 20:54:51 +0900 Subject: Fixes exponentiation operator --- .gitignore | 3 ++- bin/phpunit | 1 + composer.json | 9 +++++++++ src/NXP/Classes/Token/TokenDegree.php | 4 ++-- tests/MathTest.php | 6 ++++++ 5 files changed, 20 insertions(+), 3 deletions(-) create mode 120000 bin/phpunit diff --git a/.gitignore b/.gitignore index 9f33dd5..83436db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -.idea/ \ No newline at end of file +.idea/ +composer.lock \ No newline at end of file diff --git a/bin/phpunit b/bin/phpunit new file mode 120000 index 0000000..4ba3256 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1 @@ +../vendor/phpunit/phpunit/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index a32dc52..dc35c2f 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,16 @@ "email": "frei@neonxp.info" } ], + "require": { + "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "~5.0" + }, "autoload": { "psr-0": {"NXP": "src/"} + }, + "config": { + "bin-dir": "bin" } } diff --git a/src/NXP/Classes/Token/TokenDegree.php b/src/NXP/Classes/Token/TokenDegree.php index 8488dcd..c31b66e 100644 --- a/src/NXP/Classes/Token/TokenDegree.php +++ b/src/NXP/Classes/Token/TokenDegree.php @@ -41,13 +41,13 @@ class TokenDegree extends AbstractOperator /** * @param InterfaceToken[] $stack - * @return $this + * @return TokenNumber */ public function execute(&$stack) { $op2 = array_pop($stack); $op1 = array_pop($stack); - $result = $op1->getValue() ^ $op2->getValue(); + $result = $op1->getValue() ** $op2->getValue(); return new TokenNumber($result); } diff --git a/tests/MathTest.php b/tests/MathTest.php index f8a271e..a83a0d4 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -33,6 +33,12 @@ class MathTest extends \PHPUnit_Framework_TestCase $this->assertEquals($calculator->execute('1 / 0'), 0); } + public function testExponentiation() + { + $calculator = new MathExecutor(); + $this->assertEquals($calculator->execute('10 ^ 2'), 100); + } + /** * Expressions data provider */ -- cgit v1.2.3