From f38fcbd7118a1a73e71b0a80fe9b6fb5e6ba9c59 Mon Sep 17 00:00:00 2001 From: Claus Due Date: Thu, 26 Jul 2018 15:47:53 +0200 Subject: [PATCH 1/2] [TASK] Extend MathExpressionNode tests with chained math Adds test cases for expressions like {a + 1 * 2}. --- .../Expression/MathExpressionNodeTest.php | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php b/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php index 6b60acdd6..36595187d 100644 --- a/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php +++ b/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php @@ -39,16 +39,21 @@ public function testEvaluateExpression($expression, array $variables, $expected) public function getEvaluateExpressionTestValues() { return [ - ['1 gabbagabbahey 1', [], 0], - ['1 + 1', [], 2], - ['2 - 1', [], 1], - ['2 % 4', [], 2], - ['2 * 4', [], 8], - ['4 / 2', [], 2], - ['4 ^ 2', [], 16], - ['a + 1', ['a' => 1], 2], - ['1 + b', ['b' => 1], 2], - ['a + b', ['a' => 1, 'b' => 1], 2], + 'Invalid operator returns zero' => ['1 gabbagabbahey 1', [], 0], + '1 + 1 = 2' => ['1 + 1', [], 2], + '1 + 1 + 1 = 3' => ['1 + 1 + 1', [], 3], + '1 + 1 * 2 = 4' => ['1 + 1 * 2', [], 4], + '2 - 1 = 1' => ['2 - 1', [], 1], + '2 % 4 = 2' => ['2 % 4', [], 2], + '2 * 4 = 8' => ['2 * 4', [], 8], + '4 / 2 = 2' => ['4 / 2', [], 2], + '4 ^ 2 = 16' => ['4 ^ 2', [], 16], + '$a(1) + 1 = 2' => ['a + 1', ['a' => 1], 2], + '$a(1) + $a(1) + 1 = 3' => ['a + a + 1', ['a' => 1], 3], + '1 + $b(1) = 2' => ['1 + b', ['b' => 1], 2], + '$a(1) + $b(1) = 2' => ['a + b', ['a' => 1, 'b' => 1], 2], + '$a(true) + 1 = 2' => ['a + 1', ['a' => true], 2], + '$a(false) + 1 = 1' => ['a + 1', ['a' => false], 1], ]; } } From f80d64d521ea9799810baac9760863425bd08c3c Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Mon, 30 Jul 2018 09:36:23 +0200 Subject: [PATCH 2/2] [TASK] Use explaining dataset titles --- .../Expression/MathExpressionNodeTest.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php b/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php index 36595187d..1d4f70e76 100644 --- a/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php +++ b/tests/Unit/Core/Parser/SyntaxTree/Expression/MathExpressionNodeTest.php @@ -40,20 +40,20 @@ public function getEvaluateExpressionTestValues() { return [ 'Invalid operator returns zero' => ['1 gabbagabbahey 1', [], 0], - '1 + 1 = 2' => ['1 + 1', [], 2], - '1 + 1 + 1 = 3' => ['1 + 1 + 1', [], 3], - '1 + 1 * 2 = 4' => ['1 + 1 * 2', [], 4], - '2 - 1 = 1' => ['2 - 1', [], 1], - '2 % 4 = 2' => ['2 % 4', [], 2], - '2 * 4 = 8' => ['2 * 4', [], 8], - '4 / 2 = 2' => ['4 / 2', [], 2], - '4 ^ 2 = 16' => ['4 ^ 2', [], 16], - '$a(1) + 1 = 2' => ['a + 1', ['a' => 1], 2], - '$a(1) + $a(1) + 1 = 3' => ['a + a + 1', ['a' => 1], 3], - '1 + $b(1) = 2' => ['1 + b', ['b' => 1], 2], - '$a(1) + $b(1) = 2' => ['a + b', ['a' => 1, 'b' => 1], 2], - '$a(true) + 1 = 2' => ['a + 1', ['a' => true], 2], - '$a(false) + 1 = 1' => ['a + 1', ['a' => false], 1], + 'Simple addition' => ['1 + 1', [], 2], + 'Chained addition' => ['1 + 1 + 1', [], 3], + 'Multiplication before addition' => ['1 + 1 * 2', [], 4], + 'Subtraction' => ['2 - 1', [], 1], + 'Modulo' => ['2 % 4', [], 2], + 'Multiplication' => ['2 * 4', [], 8], + 'Division' => ['4 / 2', [], 2], + 'Exponentiation' => ['4 ^ 2', [], 16], + 'Simple variable (first) addition' => ['a + 1', ['a' => 1], 2], + 'Simple variable (last) addition' => ['1 + b', ['b' => 1], 2], + 'Multiple variable addition' => ['a + a + 1', ['a' => 1], 3], + 'Variable only addition' => ['a + b', ['a' => 1, 'b' => 1], 2], + 'Addition with boolean "true"' => ['a + 1', ['a' => true], 2], + 'Addition with boolean "false"' => ['a + 1', ['a' => false], 1], ]; } }