From e677290ed9827d60e1c89c6d1ef6fdcb42e93239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Gomes=20da=20Silva=20Lisboa?= Date: Wed, 14 Jul 2021 09:45:25 -0300 Subject: [PATCH] Filter for arithmetic operations #28 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Flávio Gomes da Silva Lisboa --- src/FourOperations.php | 36 ++++++++++++++++++++++-------------- test/FourOperationsTest.php | 26 +++++++++++++++++++++----- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/FourOperations.php b/src/FourOperations.php index c63ed325..d33762b3 100644 --- a/src/FourOperations.php +++ b/src/FourOperations.php @@ -1,44 +1,52 @@ options = $options; } - + public function filter($value) { $value = (float) $value; $operand = (float) $this->options['value']; - switch ($this->options['operation']){ + switch ($this->options['operation']) { case self::ADD: return ($value + $operand); case self::SUB: diff --git a/test/FourOperationsTest.php b/test/FourOperationsTest.php index 4032e479..7ab95796 100644 --- a/test/FourOperationsTest.php +++ b/test/FourOperationsTest.php @@ -6,17 +6,33 @@ class FourOperationsTest extends TestCase { + public function testOperations(): void { - $filter = new FourOperations(['operation'=>'add','value'=>4]); + $filter = new FourOperations([ + 'operation' => 'add', + 'value' => 4 + ]); $this->assertEquals(9, $filter->filter(5)); - $filter = new FourOperations(['operation'=>'sub','value'=>3]); + $filter = new FourOperations([ + 'operation' => 'sub', + 'value' => 3 + ]); $this->assertEquals(7, $filter->filter(10)); - $filter = new FourOperations(['operation'=>'mul','value'=>5]); + $filter = new FourOperations([ + 'operation' => 'mul', + 'value' => 5 + ]); $this->assertEquals(30, $filter->filter(6)); - $filter = new FourOperations(['operation'=>'div','value'=>12]); + $filter = new FourOperations([ + 'operation' => 'div', + 'value' => 12 + ]); $this->assertEquals(12, $filter->filter(144)); - $filter = new FourOperations(['operation'=>'mod','value'=>2]); + $filter = new FourOperations([ + 'operation' => 'mod', + 'value' => 2 + ]); $this->assertEquals(1, $filter->filter(3)); } } \ No newline at end of file