From a8bdd54346f8b932ede78f7a9a0764ee336fd281 Mon Sep 17 00:00:00 2001 From: NeonXP Date: Thu, 14 Mar 2013 04:27:37 +0400 Subject: Initial commit --- NXP/Tests/MathTest.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 NXP/Tests/MathTest.php (limited to 'NXP/Tests') diff --git a/NXP/Tests/MathTest.php b/NXP/Tests/MathTest.php new file mode 100644 index 0000000..6ab67ee --- /dev/null +++ b/NXP/Tests/MathTest.php @@ -0,0 +1,60 @@ +generateExpression(); + print "Test #$i. Expression: '$expression'\t"; + + eval('$result1 = ' . $expression . ';'); + print "PHP result: $result1 \t"; + $result2 = $calculator->execute($expression); + print "NXP Math Executor result: $result2\n"; + $this->assertEquals($result1, $result2); + } + } + + private function generateExpression() + { + $operators = [ '+', '-', '*', '/' ]; + $number = true; + $expression = ''; + $brackets = 0; + for ($i = 1; $i < rand(1,10)*2; $i++) { + if ($number) { + $expression .= rand(1,100)*0.5; + } else { + $expression .= $operators[rand(0,3)]; + } + $number = !$number; + $rand = rand(1,5); + if (($rand == 1) && ($number)) { + $expression .= '('; + $brackets++; + } elseif (($rand == 2) && (!$number) && ($brackets > 0)) { + $expression .= ')'; + $brackets--; + } + } + if ($number) { + $expression .= rand(1,100)*0.5; + } + $expression .= str_repeat(')', $brackets); + + return $expression; + } +} \ No newline at end of file -- cgit v1.2.3