aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordiman3210 <diman-3210@mail.ru>2020-10-20 01:48:30 +0300
committerGitHub <noreply@github.com>2020-10-20 01:48:30 +0300
commite28c1bf9e7683e3b1adc3f487c3a993c0d8b2b2d (patch)
tree3351aecda276f666b821a57ed79b0e5d8d95f9d3 /tests
parentd9eb39e38d090eaf00904a37d04aef6db4ceadac (diff)
add new functions and aliases to the old functions (#76)
* add new functions and aliases to the old functions * add tests for new functions
Diffstat (limited to 'tests')
-rw-r--r--tests/MathTest.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/MathTest.php b/tests/MathTest.php
index 4ea0cb0..65d8eac 100644
--- a/tests/MathTest.php
+++ b/tests/MathTest.php
@@ -526,4 +526,45 @@ class MathTest extends TestCase
$this->expectException(MathExecutorException::class);
$calculator->setVar('resource', tmpfile());
}
+
+ /**
+ * @dataProvider providerExpressionValues
+ */
+ public function testCalculatingValues($expression, $value)
+ {
+ $calculator = new MathExecutor();
+
+ try {
+ $result = $calculator->execute($expression);
+ } catch (Exception $e) {
+ $this->fail(sprintf("Exception: %s (%s:%d), expression was: %s", get_class($e), $e->getFile(), $e->getLine(), $expression));
+ }
+ $this->assertEquals($value, $result, "${expression} did not evaluate to {$value}");
+ }
+
+ /**
+ * Expressions data provider
+ *
+ * Most tests can go in here. The idea is that each expression will be evaluated by MathExecutor and by PHP with eval.
+ * The results should be the same. If they are not, then the test fails. No need to add extra test unless you are doing
+ * something more complex and not a simple mathmatical expression.
+ */
+ public function providerExpressionValues()
+ {
+ return [
+ ['arcsec(4)', 1.3181160716528],
+ ['arccsc(4)', 0.2526802551421],
+ ['arctan(4)', 1.3258176636680],
+ ['cosec(4)', -1.3213487088109],
+ ['cotan(4)', 0.8636911544506],
+ ['sec(4)', -1.5298856564664],
+ ['tg(4)', 1.1578212823496],
+ ['arcsin(0.5)', 0.5235987755983],
+ ['arccosec(4)', 0.2526802551421],
+ ['arccos(0.5)', 1.0471975511966],
+ ['arccotan(4)', 0.2449786631269],
+ ['ln(2)', 0.6931471805599],
+ ['lg(2)', 0.3010299956639],
+ ];
+ }
} \ No newline at end of file