aboutsummaryrefslogtreecommitdiff
path: root/tests/MathTest.php
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2020-07-27 05:14:51 +0300
committerGitHub <noreply@github.com>2020-07-27 05:14:51 +0300
commitb38893d672f479314e8b9f254457b8b9755c781f (patch)
tree138f34848c23a8c0595405f23fe2e0e006f94c33 /tests/MathTest.php
parentc1e07f254a4e952868be8240080661628aef8e69 (diff)
Release prep (#69)V2.1.0
* String comparison unit tests * getVars and getFunctions sanity checks * Add dynamic variable documentation
Diffstat (limited to 'tests/MathTest.php')
-rw-r--r--tests/MathTest.php39
1 files changed, 35 insertions, 4 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index d76a57c..2669ccd 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -416,13 +416,21 @@ class MathTest extends TestCase
$this->assertEquals(true, $calculator->execute('"hello world" == "hello world"'));
$this->assertEquals(false, $calculator->execute('"hello world" == "hola mundo"'));
$this->assertEquals(true, $calculator->execute('"hello world" != "hola mundo"'));
+ $this->assertEquals(true, $calculator->execute('"a" < "b"'));
+ $this->assertEquals(false, $calculator->execute('"a" > "b"'));
+ $this->assertEquals(true, $calculator->execute('"a" <= "b"'));
+ $this->assertEquals(false, $calculator->execute('"a" >= "b"'));
+ $this->assertEquals(true, $calculator->execute('"A" != "a"'));
}
public function testVarStringComparison()
{
$calculator = new MathExecutor();
- $calculator->setVar('var', 0);
- $this->assertEquals($calculator->execute('0 == "a"'), $calculator->execute('var == "a"'));
+ $calculator->setVar('var', 97);
+ $this->assertEquals(false, $calculator->execute('97 == "a"'));
+ $this->assertEquals(false, $calculator->execute('$var == "a"'));
+ $calculator->setVar('var', 'a');
+ $this->assertEquals(true, $calculator->execute('$var == "a"'));
}
public function testOnVarNotFound()
@@ -432,9 +440,8 @@ class MathTest extends TestCase
function ($varName) {
if ($varName == 'undefined') {
return 3;
- } else {
- return null;
}
+ return null;
}
);
$this->assertEquals(15, $calculator->execute('5 * undefined'));
@@ -446,4 +453,28 @@ class MathTest extends TestCase
$this->assertEquals(1, $calculator->execute('1 - 0'));
$this->assertEquals(1, $calculator->execute('1-0'));
}
+
+ public function testGetFunctionsReturnsArray()
+ {
+ $calculator = new MathExecutor();
+ $this->assertIsArray($calculator->getFunctions());
+ }
+
+ public function testGetFunctionsReturnsFunctions()
+ {
+ $calculator = new MathExecutor();
+ $this->assertGreaterThan(40, count($calculator->getFunctions()));
+ }
+
+ public function testGetVarsReturnsArray()
+ {
+ $calculator = new MathExecutor();
+ $this->assertIsArray($calculator->getVars());
+ }
+
+ public function testGetVarsReturnsCount()
+ {
+ $calculator = new MathExecutor();
+ $this->assertGreaterThan(1, count($calculator->getVars()));
+ }
}