aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJavier Marín <javier@marinros.com>2020-09-15 03:47:26 +0300
committerBruce Wells <brucekwells@gmail.com>2020-09-16 04:14:44 +0300
commit8fc77e54e01be2bfc6c2d5938fcd7735d4c9b3dd (patch)
tree752ca6f1602526ce36e38b289f2bb54630c4a0e3 /tests
parent8a2cae984f77ed55195bed071b12a165fa532561 (diff)
Improved support for null variables (#72)
* Added handler to define not found variables Added support for string variables Fixed strings and ints comparison error * Check if variables have scalar types (int, float, string and bool) Better $onVarNotFound logic * Better support for null variables * Better support for null variables * Better support for null variables
Diffstat (limited to 'tests')
-rw-r--r--tests/MathTest.php42
1 files changed, 21 insertions, 21 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 8f5665b..c519c5c 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -237,8 +237,8 @@ class MathTest extends TestCase
$calculator = new MathExecutor();
$this->expectException(DivisionByZeroException::class);
$calculator->execute('10 / 0');
- $calculator->setVar('one', 1)->setVar('zero', 0);
- $this->assertEquals(0.0, $calculator->execute('$one / $zero'));
+ $calculator->setVar('one', 1)->setVar('zero', 0);
+ $this->assertEquals(0.0, $calculator->execute('$one / $zero'));
}
public function testVariableIncorrectExpressionException()
@@ -337,19 +337,19 @@ class MathTest extends TestCase
$this->assertEquals(2.71828182846, $calculator->execute('$e'));
$this->assertEquals(2.71828182846, $calculator->execute('e'));
$calculator->setVars([
- 'trx_amount' => 100000.01,
- 'ten' => 10,
- 'nine' => 9,
- 'eight' => 8,
- 'seven' => 7,
- 'six' => 6,
- 'five' => 5,
- 'four' => 4,
- 'three' => 3,
- 'two' => 2,
- 'one' => 1,
- 'zero' => 0,
- ]);
+ 'trx_amount' => 100000.01,
+ 'ten' => 10,
+ 'nine' => 9,
+ 'eight' => 8,
+ 'seven' => 7,
+ 'six' => 6,
+ 'five' => 5,
+ 'four' => 4,
+ 'three' => 3,
+ 'two' => 2,
+ 'one' => 1,
+ 'zero' => 0,
+ ]);
$this->assertEquals(100000.01, $calculator->execute('$trx_amount'));
$this->assertEquals(10 - 9, $calculator->execute('$ten - $nine'));
$this->assertEquals(9 - 10, $calculator->execute('$nine - $ten'));
@@ -374,8 +374,8 @@ class MathTest extends TestCase
$calculator->addFunction(
'round',
function ($value, $decimals) {
- return round($value, $decimals);
- }
+ return round($value, $decimals);
+ }
);
$expression = 'round(100 * 1.111111, 2)';
$phpResult = 0;
@@ -403,9 +403,9 @@ class MathTest extends TestCase
$calculator->addFunction(
'test',
function ($arg) use ($testString) {
- $this->assertEquals($testString, $arg);
- return 0;
- }
+ $this->assertEquals($testString, $arg);
+ return 0;
+ }
);
$calculator->execute('test("' . $testString . '")'); // single quotes
$calculator->execute("test('" . $testString . "')"); // double quotes
@@ -526,4 +526,4 @@ class MathTest extends TestCase
$this->expectException(MathExecutorException::class);
$calculator->setVar('resource', tmpfile());
}
-}
+} \ No newline at end of file