Fixes exponentiation operator

This commit is contained in:
ochi51 2017-09-12 20:54:51 +09:00
parent 1086fccc92
commit 8d602b30dd
5 changed files with 20 additions and 3 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
vendor/ vendor/
.idea/ .idea/
composer.lock

1
bin/phpunit Symbolic link
View file

@ -0,0 +1 @@
../vendor/phpunit/phpunit/phpunit

View file

@ -11,7 +11,16 @@
"email": "frei@neonxp.info" "email": "frei@neonxp.info"
} }
], ],
"require": {
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "~5.0"
},
"autoload": { "autoload": {
"psr-0": {"NXP": "src/"} "psr-0": {"NXP": "src/"}
},
"config": {
"bin-dir": "bin"
} }
} }

View file

@ -41,13 +41,13 @@ class TokenDegree extends AbstractOperator
/** /**
* @param InterfaceToken[] $stack * @param InterfaceToken[] $stack
* @return $this * @return TokenNumber
*/ */
public function execute(&$stack) public function execute(&$stack)
{ {
$op2 = array_pop($stack); $op2 = array_pop($stack);
$op1 = array_pop($stack); $op1 = array_pop($stack);
$result = $op1->getValue() ^ $op2->getValue(); $result = $op1->getValue() ** $op2->getValue();
return new TokenNumber($result); return new TokenNumber($result);
} }

View file

@ -33,6 +33,12 @@ class MathTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($calculator->execute('1 / 0'), 0); $this->assertEquals($calculator->execute('1 / 0'), 0);
} }
public function testExponentiation()
{
$calculator = new MathExecutor();
$this->assertEquals($calculator->execute('10 ^ 2'), 100);
}
/** /**
* Expressions data provider * Expressions data provider
*/ */