aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2022-05-28 23:02:04 +0300
committerGitHub <noreply@github.com>2022-05-28 23:02:04 +0300
commitcbada2b920782bdfd2f18ef88c09e24ae4840f4a (patch)
tree73c3405cb2ba06022fb9c61e5bbeb3cf3ccc61e3 /tests/MathTest.php
parentd1b060749e58a09bc437f85152d54e40c163efb0 (diff)
Space should end open numbers (#113)v2.2.2
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php43
1 files changed, 36 insertions, 7 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index e68fdb8..7af7c59 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -26,7 +26,7 @@ class MathTest extends TestCase
/**
* @dataProvider providerExpressions
*/
- public function testCalculating($expression) : void
+ public function testCalculating(string $expression) : void
{
$calculator = new MathExecutor();
@@ -250,18 +250,47 @@ class MathTest extends TestCase
];
}
- public function testUnknownFunctionException() : void
+ /**
+ * @dataProvider incorrectExpressions
+ */
+ public function testIncorrectExpressionException(string $expression) : void
{
$calculator = new MathExecutor();
- $this->expectException(UnknownFunctionException::class);
- $calculator->execute('1 * fred("wilma") + 3');
+ $calculator->setVars(['a' => 12, 'b' => 24]);
+ $this->expectException(IncorrectExpressionException::class);
+ $calculator->execute($expression);
+ }
+
+ /**
+ * Incorrect Expressions data provider
+ *
+ * These expressions should not pass validation
+ */
+ public function incorrectExpressions()
+ {
+ return [
+ ['1 * + '],
+ [' 2 3'],
+ ['2 3 '],
+ [' 2 4 3 '],
+ ['$a $b'],
+ ['$a [3, 4, 5]'],
+ ['$a (3 + 4)'],
+ ['$a "string"'],
+ ['5 "string"'],
+ ['"string" $a'],
+ ['$a round(12.345)'],
+ ['round(12.345) $a'],
+ ['4 round(12.345)'],
+ ['round(12.345) 4'],
+ ];
}
- public function testIncorrectExpressionException() : void
+ public function testUnknownFunctionException() : void
{
$calculator = new MathExecutor();
- $this->expectException(IncorrectExpressionException::class);
- $calculator->execute('1 * + ');
+ $this->expectException(UnknownFunctionException::class);
+ $calculator->execute('1 * fred("wilma") + 3');
}
public function testZeroDivision() : void