From 18b03f870ac7287d43fe014abc4a6ad0d5161a68 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 15:06:17 +0700 Subject: [PATCH 01/14] Add test cases for AddController --- tests/Feature/AddControllerTest.php | 97 +++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/Feature/AddControllerTest.php diff --git a/tests/Feature/AddControllerTest.php b/tests/Feature/AddControllerTest.php new file mode 100644 index 0000000..9bf9d85 --- /dev/null +++ b/tests/Feature/AddControllerTest.php @@ -0,0 +1,97 @@ +get('/add'); + + $response->assertStatus(200) + ->assertSee('Add (บวก)') + ->assertSee('+') + ->assertSee('-') + ->assertSee('x') + ->assertSee('/') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/add', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('name="num1" value="3" readonly') + # ->assertSee('3') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/add', ['num1' => 5]); + + $response->assertStatus(200) + ->assertSee('name="num1" value="5" readonly') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/add', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/add', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeAdded() + { + $response = $this->post('/add', ['num1' => 3.2, 'num2' => 1.8]); + + $response->assertStatus(200) + ->assertSee(5) + ; + + $response = $this->post('/add', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee(4) + ; + + $response = $this->post('/add', ['num1' => 3.0, 'num2' => 1]); + $response->assertStatus(200) + ->assertSee(4) + ; + + $response = $this->post('/add', ['num1' => 0.0, 'num2' => 0.0]); + $response->assertStatus(200) + ->assertSee(0) + ; + } + + public function testNegativeShouldBeAdd() + { + $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee(0) + ; + + $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee(0) + ; + } + +} From e22749f07097b4e90504f2c6993e2d81fe816cd7 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 15:07:19 +0700 Subject: [PATCH 02/14] Clean temp file --- .DS_Store | Bin 8196 -> 8196 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index c3e5a9aaaffae8307622ec55154c89f4f388d0fa..211e5ac6875d68a5e4c0357f7a29c20e081a828b 100644 GIT binary patch delta 68 zcmZp1XmOa}&nUGqU^hRb)Mg%m=d6>Dit_W61sCPz~{_ F7y%V@7YqOZ delta 40 qcmZp1XmOa}&nUSuU^hRb?Z`F7XD&kp=)6O%37z From e241178cccb8aa6ac6f186d14a97a65e56936696 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 15:08:27 +0700 Subject: [PATCH 03/14] Reformat code --- app/Http/Controllers/AddController.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/AddController.php b/app/Http/Controllers/AddController.php index 098e1e7..b95e206 100644 --- a/app/Http/Controllers/AddController.php +++ b/app/Http/Controllers/AddController.php @@ -7,22 +7,22 @@ class AddController extends Controller{ - public function calculate($ans = null){ - if (strpos($ans, '_') !== false) { - $new = (float)str_replace('_','.',$ans); - } - else - $new = $ans; + public function calculate($ans = null){ + if (strpos($ans, '_') !== false) { + $new = (float)str_replace('_','.',$ans); + } + else + $new = $ans; - if(Input::has('num1') && Input::has('num2')) - $new = Input::get('num1') + Input::get('num2'); - elseif(Input::has('num1')) - $new = Input::get('num1'); + if(Input::has('num1') && Input::has('num2')) + $new = Input::get('num1') + Input::get('num2'); + elseif(Input::has('num1')) + $new = Input::get('num1'); - $route = str_replace(".","_",strval($new)); + $route = str_replace(".","_",strval($new)); - return view('add', array('ans' => $new, 'route' => $route)); - } + return view('add', array('ans' => $new, 'route' => $route)); + } } From 10eb433e89a819069c938fc74593bc07069d9fe5 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 15:26:04 +0700 Subject: [PATCH 04/14] Commit test case for minus --- tests/Feature/MinusControllerTest.php | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/Feature/MinusControllerTest.php diff --git a/tests/Feature/MinusControllerTest.php b/tests/Feature/MinusControllerTest.php new file mode 100644 index 0000000..a6ba06d --- /dev/null +++ b/tests/Feature/MinusControllerTest.php @@ -0,0 +1,104 @@ +get('/minus'); + + $response->assertStatus(200) + ->assertSee('Minus (ลบ)') + ->assertSee('=') + ->assertSee('+') + ->assertSee('-') + ->assertSee('x') + ->assertSee('/') + ; + } + + public function testMinusAnswerShouldDisplay() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => 1]); + + $response->assertStatus(200) + ->assertSee('name="num1" value="2" readonly') + # ->assertSee('3') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/minus', ['num1' => 0]); + + $response->assertStatus(200) + ->assertSee('name="num1" value="0" readonly') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => 'a']); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/minus', ['num1' => 'a', 'num2' => 1]); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/minus', ['num1' => 'a', 'num2' => 'b']); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeMinus() + { + $response = $this->post('/minus', ['num1' => 3.2, 'num2' => 1.2]); + $response->assertStatus(200) + ->assertSee(2) + ; + + $response = $this->post('/minus', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee(2) + ; + + $response = $this->post('/minus', ['num1' => 3.0, 'num2' => 1]); + $response->assertStatus(200) + ->assertSee(2) + ; + + $response = $this->post('/minus', ['num1' => 0.0, 'num2' => 0.0]); + $response->assertStatus(200) + ->assertSee(0) + ; + } + + public function testNegativeShouldBeMinus() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee(2) + ; + + $response = $this->post('/minus', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee(0) + ; + + $response = $this->post('/minus', ['num1' => -1, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee(-1) + ; + } +} From 7a67836130820ac2e80a7a4012c1034c09ad9fb4 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 16:07:12 +0700 Subject: [PATCH 05/14] Update for instruction --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index e69de29..7f8ed81 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,37 @@ +# Calculator + +เว็บแอปพลิเคชันเพื่อแสดงตัวอย่างการเขียนกรณีทดสอบ + +## ความต้องการเบื้องต้น +| รายการซอฟต์แวร์ | รุ่นขั้นต่ำ | รุ่นที่แนะนำ | รุ่นที่ใช้พัฒนา | +|---------------|:------:|:--------:|:---------:| +| PHP | >=5.5 | 5.5 | 7 | +| composer | 1.4.2 | 1.4.2 | 1.4.2 | + +## การติดตั้ง + +1. ดาวน์โหลด ```we-inc/calculator``` ด้วยคำสั่ง + ``` + git clone https://github.com/we-inc/calculator + ``` + +1. อัพเดต lib ด้วยคำสั่ง ```composer``` + ``` + cd calculator && \ + composer update + ``` + +1. กรณีทดสอบจะอยู่อยู่ภายในโฟลเดอร์ + ``` + + tests + + Features + | + AddControllerTest.php + | + MinusControllerTest.php + + Unit + ``` + +1. สร้างกรณีทดสอบโดยใช้คำสั่ง + ```php artisan make:test SomeTestCaseTest``` + เพื่อสร้างกรณีทดสอบสำหรับหน้าที่การใช้งานตัวไป และ + ```php artisan make:test SomeControllerTest --unit``` + สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง \ No newline at end of file From eee054b5e613255ec0fa849864bf2be50a04e6b0 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 16:11:28 +0700 Subject: [PATCH 06/14] Fix for wrong expected minus result at #10eb433 --- tests/Feature/MinusControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/MinusControllerTest.php b/tests/Feature/MinusControllerTest.php index a6ba06d..ed99826 100644 --- a/tests/Feature/MinusControllerTest.php +++ b/tests/Feature/MinusControllerTest.php @@ -98,7 +98,7 @@ public function testNegativeShouldBeMinus() $response = $this->post('/minus', ['num1' => -1, 'num2' => 2]); $response->assertStatus(200) - ->assertSee(-1) + ->assertSee(-3) ; } } From c59b01586c01cf336ff01791a62cde3622457d96 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 16:33:35 +0700 Subject: [PATCH 07/14] Add ref section --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f8ed81..def21bc 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,10 @@ ```php artisan make:test SomeTestCaseTest``` เพื่อสร้างกรณีทดสอบสำหรับหน้าที่การใช้งานตัวไป และ ```php artisan make:test SomeControllerTest --unit``` - สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง \ No newline at end of file + สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง + +## ข้อมูลเพิ่มเติม + +ข้อมูลเพิ่มเติมสำหรับกรณีทดสอบ +- [Laravel: Getting Started](https://laravel.com/docs/master/testing) +- [Illuminate: TestCase API](https://laravel.com/api/master/Illuminate/Foundation/Testing/TestCase.html) From 51b55b9b180af336e9a01f93837c28ea127b10dc Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 16:37:43 +0700 Subject: [PATCH 08/14] Update README --- README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index def21bc..10e532a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Calculator -เว็บแอปพลิเคชันเพื่อแสดงตัวอย่างการเขียนกรณีทดสอบ +เว็บแอปพลิเคชันเพื่อแสดงตัวอย่างการเขียนกรณีทดสอบ โดยใช้ `Laravel 5.4` และ `PHPUnit` เพื่อการทดสอบ ## ความต้องการเบื้องต้น | รายการซอฟต์แวร์ | รุ่นขั้นต่ำ | รุ่นที่แนะนำ | รุ่นที่ใช้พัฒนา | @@ -10,12 +10,12 @@ ## การติดตั้ง -1. ดาวน์โหลด ```we-inc/calculator``` ด้วยคำสั่ง +1. ดาวน์โหลด `we-inc/calculator` ด้วยคำสั่ง ``` git clone https://github.com/we-inc/calculator ``` -1. อัพเดต lib ด้วยคำสั่ง ```composer``` +1. อัพเดต lib ด้วยคำสั่ง `composer` ``` cd calculator && \ composer update @@ -31,9 +31,14 @@ ``` 1. สร้างกรณีทดสอบโดยใช้คำสั่ง - ```php artisan make:test SomeTestCaseTest``` + ``` + php artisan make:test SomeTestCaseTest + ``` เพื่อสร้างกรณีทดสอบสำหรับหน้าที่การใช้งานตัวไป และ - ```php artisan make:test SomeControllerTest --unit``` + + ``` + php artisan make:test SomeControllerTest --unit + ``` สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง ## ข้อมูลเพิ่มเติม From 7842837214db67ea5ad724a1d259b560b5b12e64 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 22:26:36 +0700 Subject: [PATCH 09/14] Add test instruction --- .DS_Store | Bin 8196 -> 8196 bytes README.md | 7 +++++++ 2 files changed, 7 insertions(+) diff --git a/.DS_Store b/.DS_Store index 211e5ac6875d68a5e4c0357f7a29c20e081a828b..5533773707cc02fc744dc6e682c841c7e101b1b9 100644 GIT binary patch delta 48 zcmZp1XmQx^MOc)JA&9}1!I8m*!52vDG2}9&Fw|{k7x~A$nO))=%j7cx9-Ey-_cH+i DIRXu+ delta 42 wcmZp1XmQx^MOc`VA&9}1!I8m*!52vDG2}9&Y~~dC$Gn+U;s?v-|03+n0PpGxb^rhX diff --git a/README.md b/README.md index 10e532a..fd582c3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,13 @@ ``` สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง +1. ทดสอบซอฟต์แวร์ด้วยกรณีทดสอบที่สร้างขึ้นด้วยคำสั่ง `phpunit` ณ โฟลเดอร์ชั้นบนสุดของโปรเจค + ```php + phpunit + ``` + + เมื่อผลการทดสอบเสร็จสิ้น จะมีผลลัพธ์การดำเนินการแสดงให้ทราบ + ## ข้อมูลเพิ่มเติม ข้อมูลเพิ่มเติมสำหรับกรณีทดสอบ From 5f9e2fe357d352d6dd742e116f4a7cca8191c843 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Sun, 6 Aug 2017 22:43:16 +0700 Subject: [PATCH 10/14] Update README.md --- README.md | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fd582c3..13ee42b 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,14 @@ ## การติดตั้ง 1. ดาวน์โหลด `we-inc/calculator` ด้วยคำสั่ง - ``` + ```bash git clone https://github.com/we-inc/calculator ``` 1. อัพเดต lib ด้วยคำสั่ง `composer` - ``` + ```bash cd calculator && \ - composer update + composer update ``` 1. กรณีทดสอบจะอยู่อยู่ภายในโฟลเดอร์ @@ -30,16 +30,42 @@ + Unit ``` -1. สร้างกรณีทดสอบโดยใช้คำสั่ง - ``` +1. สร้างกรณีทดสอบโดยใช้คำสั่งด้านล่าง โดยคำสั่งนี้จะสร้างคลาสซึ่งเป็น Unit Test ชื่อ `SomeTestCaseTest` (โดยที่กรณีทดสอบนั้นต้องลงท้ายชื่อด้วย `Test`) + ```bash php artisan make:test SomeTestCaseTest ``` เพื่อสร้างกรณีทดสอบสำหรับหน้าที่การใช้งานตัวไป และ - ``` + ```bash php artisan make:test SomeControllerTest --unit ``` สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง + +1. ภายในคลาส `SomeTestCaseTest` ที่สร้างขึ้นมานั้น จะมีซอร์สโค้ดดังตัวอย่างด้านล่าง + ```php + assertTrue(true); + } + } + ``` + ด้านในจะปรากฏเมธอด `testExample()` ซึ่งเมธอดที่มีชื่อขึ้นต้นด้วย `test` นั้นจะบรรจุกรณีทดสอบ ซึ่งจะนำมาใช้ทดสอบคุณสมบัติต่าง ๆ ของซอฟต์แวร์ตามที่ต้องการ 1. ทดสอบซอฟต์แวร์ด้วยกรณีทดสอบที่สร้างขึ้นด้วยคำสั่ง `phpunit` ณ โฟลเดอร์ชั้นบนสุดของโปรเจค ```php From 15812c4fd526fcd907c0b9a7d942f0d38b55e0d6 Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Mon, 7 Aug 2017 00:28:07 +0700 Subject: [PATCH 11/14] Add dependency software --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd582c3..39ffd60 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ |---------------|:------:|:--------:|:---------:| | PHP | >=5.5 | 5.5 | 7 | | composer | 1.4.2 | 1.4.2 | 1.4.2 | +| phpunit | 6.x | 6.2.2 | 6.2.2 | -## การติดตั้ง +## ขั้นตอนการทดสอบ 1. ดาวน์โหลด `we-inc/calculator` ด้วยคำสั่ง ``` From 41cb1b475009b5581d5f8586f68de04d00beee4e Mon Sep 17 00:00:00 2001 From: Sitdhibong Laokok Date: Mon, 7 Aug 2017 00:43:12 +0700 Subject: [PATCH 12/14] Update README.md Fix php version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 666566b..b229569 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ ## ความต้องการเบื้องต้น | รายการซอฟต์แวร์ | รุ่นขั้นต่ำ | รุ่นที่แนะนำ | รุ่นที่ใช้พัฒนา | |---------------|:------:|:--------:|:---------:| -| PHP | >=5.5 | 5.5 | 7 | +| PHP | >=5.7 | 5.7 | 7 | | composer | 1.4.2 | 1.4.2 | 1.4.2 | -| phpunit | 6.x | 6.2.2 | 6.2.2 | +| phpunit | 5.7 | 5.7 | 6.2.2 | ## ขั้นตอนการทดสอบ From e76f8ad3a748433028776f5783cc04694a5f8b83 Mon Sep 17 00:00:00 2001 From: bright-coder Date: Mon, 7 Aug 2017 20:03:04 +0700 Subject: [PATCH 13/14] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=20method=20add,=20divide,=20minus=20,=20multiply?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit แก้ไข method add, divide, minus , multiply --- .DS_Store | Bin 8196 -> 8196 bytes app/.DS_Store | Bin 6148 -> 6148 bytes app/Http/.DS_Store | Bin 6148 -> 6148 bytes app/Http/Controllers/AddController.php | 28 -------- app/Http/Controllers/DivideController.php | 28 -------- app/Http/Controllers/InputController.php | 74 ++++++++++++++++++++ app/Http/Controllers/MinusController.php | 28 -------- app/Http/Controllers/MultiplyController.php | 28 -------- app/Module/Add.php | 13 ++++ app/Module/Divide.php | 12 ++++ app/Module/Minus.php | 13 ++++ app/Module/Multiply.php | 12 ++++ composer.lock | 56 +++++++-------- public/asset/equal-symbol.png | Bin 0 -> 334 bytes resources/views/add.blade.php | 27 +++---- resources/views/divide.blade.php | 27 +++---- resources/views/minus.blade.php | 29 +++----- resources/views/multiply.blade.php | 27 +++---- resources/views/welcome.blade.php | 10 ++- routes/web.php | 10 +-- tests/Feature/SomeTestCaseTest.php | 21 ++++++ tests/Unit/SomeControllerTest.php | 20 ++++++ 22 files changed, 235 insertions(+), 228 deletions(-) delete mode 100644 app/Http/Controllers/AddController.php delete mode 100644 app/Http/Controllers/DivideController.php create mode 100644 app/Http/Controllers/InputController.php delete mode 100644 app/Http/Controllers/MinusController.php delete mode 100644 app/Http/Controllers/MultiplyController.php create mode 100644 app/Module/Add.php create mode 100644 app/Module/Divide.php create mode 100644 app/Module/Minus.php create mode 100644 app/Module/Multiply.php create mode 100644 public/asset/equal-symbol.png create mode 100644 tests/Feature/SomeTestCaseTest.php create mode 100644 tests/Unit/SomeControllerTest.php diff --git a/.DS_Store b/.DS_Store index 5533773707cc02fc744dc6e682c841c7e101b1b9..ecbfb0775f9e22faa7388db175c324fe919299e1 100644 GIT binary patch delta 212 zcmZp1XmOa}&nUAoU^hRb%w!&c{TwF72098xMn;pT3(Ic)ARxmuxk99c!`RqVN5R;{ z3?w@FgMiB98^SWeoD4w>t_+S0E)2dvT8|-@A!ReChzS!XD?eO2iR?yZ yMnJtrlcx#GfwYRlWf_Xgf{XHU^7GOe7#J8QTZvuV%r5bbW%EA~dq%R&I0pb);5c9a delta 110 zcmZp1XmOa}&nUGqU^hRb)MOrk{gZ!-cy1OE{K3e0VluCA1E+X(wW*1@j)K|byJB*T zGbVo&kY}7Z`I@l2C>KKzgDZn0gA0Q%kk(_!Wk_MD+sq+i!Zg`Z{M^KbKbzSlzOiin LBjUga5%>uJcHbj} diff --git a/app/.DS_Store b/app/.DS_Store index eea122ad885a5bbe0ba38a6317cbc0b622760b0d..d770ce87a05e0f7f05ba3c853da7f49e6aed4b59 100644 GIT binary patch delta 437 zcmZoMXfc=|#>B!ku~2NHo}wrh0|Nsi1A_nqLq0@yivUGkDPzI=j!5WA){(}LK#lXPD;L1?Jkj#+EP{2^akO|QVF%qt4C7K=<1`nXx z5{3d)b&TRX$Ocq31C0QN3j-%Z07DVbqB5X&Qh**SVkky)Xe+Wi zfou+jP+)L@RO$hPAp^r>pV8DaOe}x8nVo~50~jg5fd9@snP0?_186rBP$9$S2$40+ E0Mco26951J delta 101 zcmZoMXfc=|#>B)qu~2NHo}wrd0|Nsi1A_oVQh9MfQcivnkbiPx;c~{w1|lqzXR^%T zFf%jKQ7|$xoNUP&xmkomm}O$ao6YPT{2V|-HVblmXP(S2;>ZEi1~P|bbA-qmW&rQ{ B7vBH? diff --git a/app/Http/.DS_Store b/app/Http/.DS_Store index fc608b132645155d5bea32e4250ef50bfb034cfa..7aa839db8e52f16c29bd702224dcbacadb7efa6b 100644 GIT binary patch delta 174 zcmZoMXfc@J&&awlU^gQp>tr4#DH+e4{N$vZ{3Hej1_2V8FltRIrl6*w|D@ z!PvxX@?NI&WG)78hE#?khCCpd!=T4dz>vXEfM&!>WFvrVE(TwQOokL7%mL~uXGjF< WPes+kD2~vxS&`X`Wiva+Uw#08=`p$h delta 50 zcmZoMXfc@J&&aefU^nAr0}+2*6pV}vCx2#2-+YAGnPp $new, 'route' => $route)); - } - -} diff --git a/app/Http/Controllers/DivideController.php b/app/Http/Controllers/DivideController.php deleted file mode 100644 index 75ee54d..0000000 --- a/app/Http/Controllers/DivideController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/InputController.php b/app/Http/Controllers/InputController.php new file mode 100644 index 0000000..64689f1 --- /dev/null +++ b/app/Http/Controllers/InputController.php @@ -0,0 +1,74 @@ +calculate($num1,$num2); + } + + return view('add', array('answer' => $answer)); + } + + public function minus(){ + + $minus = new Minus(); + + $answer = null; + $num1 = Input::has('num1') ? Input::get('num1') : NULL ; + $num2 = Input::has('num2') ? Input::get('num2') : NULL ; + if($num1 !== NULL && $num2 !== NULL){ + $answer = $minus->calculate($num1,$num2); + } + + return view('minus', array('answer' => $answer)); + } + + public function multiply(){ + + $multiply = new Multiply(); + + $answer = null; + $num1 = Input::has('num1') ? Input::get('num1') : NULL ; + $num2 = Input::has('num2') ? Input::get('num2') : NULL ; + if($num1 !== NULL && $num2 !== NULL){ + $answer = $multiply->calculate($num1,$num2); + } + + return view('multiply', array('answer' => $answer)); + } + + public function divide(){ + + $divide = new Divide(); + + $answer = null; + $num1 = Input::has('num1') ? Input::get('num1') : NULL ; + $num2 = Input::has('num2') ? Input::get('num2') : NULL ; + if($num1 !== NULL && $num2 !== NULL && $num2 != 0){ + $answer = $divide->calculate($num1,$num2); + } + + return view('divide', array('answer' => $answer)); + } + +} + + +?> \ No newline at end of file diff --git a/app/Http/Controllers/MinusController.php b/app/Http/Controllers/MinusController.php deleted file mode 100644 index e4e93de..0000000 --- a/app/Http/Controllers/MinusController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/MultiplyController.php b/app/Http/Controllers/MultiplyController.php deleted file mode 100644 index 29928ff..0000000 --- a/app/Http/Controllers/MultiplyController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Module/Add.php b/app/Module/Add.php new file mode 100644 index 0000000..14eaaff --- /dev/null +++ b/app/Module/Add.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/app/Module/Divide.php b/app/Module/Divide.php new file mode 100644 index 0000000..37acc61 --- /dev/null +++ b/app/Module/Divide.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/app/Module/Minus.php b/app/Module/Minus.php new file mode 100644 index 0000000..8cd2b55 --- /dev/null +++ b/app/Module/Minus.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/app/Module/Multiply.php b/app/Module/Multiply.php new file mode 100644 index 0000000..97bcc11 --- /dev/null +++ b/app/Module/Multiply.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/composer.lock b/composer.lock index 91e43c9..09fac84 100644 --- a/composer.lock +++ b/composer.lock @@ -237,16 +237,16 @@ }, { "name": "laravel/framework", - "version": "v5.4.31", + "version": "v5.4.32", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9" + "reference": "b8300578d159199b1195413b67318c79068cd24d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9", - "reference": "fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9", + "url": "https://api.github.com/repos/laravel/framework/zipball/b8300578d159199b1195413b67318c79068cd24d", + "reference": "b8300578d159199b1195413b67318c79068cd24d", "shasum": "" }, "require": { @@ -362,7 +362,7 @@ "framework", "laravel" ], - "time": "2017-08-02T15:24:31+00:00" + "time": "2017-08-03T12:59:42+00:00" }, { "name": "laravel/tinker", @@ -483,16 +483,16 @@ }, { "name": "league/flysystem", - "version": "1.0.40", + "version": "1.0.41", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61" + "reference": "f400aa98912c561ba625ea4065031b7a41e5a155" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/3828f0b24e2c1918bb362d57a53205d6dc8fde61", - "reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/f400aa98912c561ba625ea4065031b7a41e5a155", + "reference": "f400aa98912c561ba625ea4065031b7a41e5a155", "shasum": "" }, "require": { @@ -513,13 +513,13 @@ "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", - "league/flysystem-copy": "Allows you to use Copy.com storage", "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", "league/flysystem-webdav": "Allows you to use WebDAV storage", "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", - "spatie/flysystem-dropbox": "Allows you to use Dropbox storage" + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" }, "type": "library", "extra": { @@ -562,7 +562,7 @@ "sftp", "storage" ], - "time": "2017-04-28T10:15:08+00:00" + "time": "2017-08-06T17:41:04+00:00" }, { "name": "monolog/monolog", @@ -960,16 +960,16 @@ }, { "name": "ramsey/uuid", - "version": "3.6.1", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "4ae32dd9ab8860a4bbd750ad269cba7f06f7934e" + "reference": "0ef23d1b10cf1bc576e9d865a7e9c47982c5715e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/4ae32dd9ab8860a4bbd750ad269cba7f06f7934e", - "reference": "4ae32dd9ab8860a4bbd750ad269cba7f06f7934e", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/0ef23d1b10cf1bc576e9d865a7e9c47982c5715e", + "reference": "0ef23d1b10cf1bc576e9d865a7e9c47982c5715e", "shasum": "" }, "require": { @@ -1038,7 +1038,7 @@ "identifier", "uuid" ], - "time": "2017-03-26T20:37:53+00:00" + "time": "2017-08-04T13:39:04+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -2251,22 +2251,22 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "46f7e8bb075036c92695b15a1ddb6971c751e585" + "reference": "183824db76118b9dddffc7e522b91fa175f75119" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/46f7e8bb075036c92695b15a1ddb6971c751e585", - "reference": "46f7e8bb075036c92695b15a1ddb6971c751e585", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/183824db76118b9dddffc7e522b91fa175f75119", + "reference": "183824db76118b9dddffc7e522b91fa175f75119", "shasum": "" }, "require": { "php": ">=5.5", "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/type-resolver": "^0.3.0", "webmozart/assert": "^1.0" }, "require-dev": { @@ -2292,20 +2292,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-07-15T11:38:20+00:00" + "time": "2017-08-04T20:55:59+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "0.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773", + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773", "shasum": "" }, "require": { @@ -2339,7 +2339,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "time": "2017-06-03T08:32:36+00:00" }, { "name": "phpspec/prophecy", diff --git a/public/asset/equal-symbol.png b/public/asset/equal-symbol.png new file mode 100644 index 0000000000000000000000000000000000000000..47125af4764773f2367584c8e688490ea9787dc6 GIT binary patch literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6SkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YDR+uenMVO6iP5s=4O z;1O92wCOqsGdgL^t^f+Mmw5WRvOnZt=Vsy-z2zzb6q50DaSYKopPaBj#Nglm{&+@V zMPZF_1BnA4IM^BVbXm9)qi5Ct)v1=aMwFx^mZVxG7o`Fz1|tJQb6o=qT?6wFLqjVA zBP&BgZ6Il2kngY_N&PEETh{4m<&t;ucLK6U&?o Add (บวก) - {{ Form::open(array('action'=> 'AddController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@add','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

+

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/divide.blade.php b/resources/views/divide.blade.php index 4168f66..ee6f69e 100644 --- a/resources/views/divide.blade.php +++ b/resources/views/divide.blade.php @@ -75,14 +75,10 @@
Divide (หาร)
- {{ Form::open(array('action'=> 'DivideController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@divide','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

/

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/minus.blade.php b/resources/views/minus.blade.php index ca56703..7f93edf 100644 --- a/resources/views/minus.blade.php +++ b/resources/views/minus.blade.php @@ -75,14 +75,10 @@
Minus (ลบ)
- {{ Form::open(array('action'=> 'MinusController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@minus','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

-

@@ -91,27 +87,20 @@
- +
-
- {{ Form::close() }} +
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/multiply.blade.php b/resources/views/multiply.blade.php index 202b06d..ce6dfab 100644 --- a/resources/views/multiply.blade.php +++ b/resources/views/multiply.blade.php @@ -75,14 +75,10 @@
Multiply (คูณ)
- {{ Form::open(array('action'=> 'MultiplyController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@multiply','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

x

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 369d0f1..eadda77 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -83,12 +83,10 @@ diff --git a/routes/web.php b/routes/web.php index 9824d8f..ce6902f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,12 +13,12 @@ Route::get('/', function () { return view('welcome'); -}); +})->name('home'); -Route::match(['get','post'],'add/{ans?}','AddController@calculate')->name('add'); +Route::match(['get','post'],'add','InputController@add')->name('add'); -Route::match(['get','post'],'minus/{ans?}','MinusController@calculate')->name('minus'); +Route::match(['get','post'],'minus','InputController@minus')->name('minus'); -Route::match(['get','post'],'multiply/{ans?}','MultiplyController@calculate')->name('multiply'); +Route::match(['get','post'],'multiply','InputController@multiply')->name('multiply'); -Route::match(['get','post'],'divide/{ans?}','DivideController@calculate')->name('divide'); \ No newline at end of file +Route::match(['get','post'],'divide','InputController@divide')->name('divide'); \ No newline at end of file diff --git a/tests/Feature/SomeTestCaseTest.php b/tests/Feature/SomeTestCaseTest.php new file mode 100644 index 0000000..2eb34f1 --- /dev/null +++ b/tests/Feature/SomeTestCaseTest.php @@ -0,0 +1,21 @@ +assertTrue(true); + } +} diff --git a/tests/Unit/SomeControllerTest.php b/tests/Unit/SomeControllerTest.php new file mode 100644 index 0000000..29d3af4 --- /dev/null +++ b/tests/Unit/SomeControllerTest.php @@ -0,0 +1,20 @@ +assertTrue(true); + } +} From 7a393e70a0ecba905fd09f73ec58cff6b6b0973a Mon Sep 17 00:00:00 2001 From: bright-coder Date: Mon, 7 Aug 2017 20:53:26 +0700 Subject: [PATCH 14/14] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=80=E0=B8=9B=E0=B8=A5=E0=B8=B5=E0=B9=88=E0=B8=A2=E0=B8=99?= =?UTF-8?q?=20TestCase=20Add,=20Minus=20=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1=20Test=20Case=20Multiply,=20Divide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/InputController.php | 55 +++++++++----- tests/Feature/AddControllerTest.php | 23 +++--- tests/Feature/DivideControllerTest.php | 97 ++++++++++++++++++++++++ tests/Feature/MinusControllerTest.php | 27 +++---- tests/Feature/MultiplyControllerTest.php | 90 ++++++++++++++++++++++ 5 files changed, 242 insertions(+), 50 deletions(-) create mode 100644 tests/Feature/DivideControllerTest.php create mode 100644 tests/Feature/MultiplyControllerTest.php diff --git a/app/Http/Controllers/InputController.php b/app/Http/Controllers/InputController.php index 64689f1..dddf9a1 100644 --- a/app/Http/Controllers/InputController.php +++ b/app/Http/Controllers/InputController.php @@ -17,11 +17,14 @@ public function add(){ $add = new Add(); $answer = null; - $num1 = Input::has('num1') ? Input::get('num1') : NULL ; - $num2 = Input::has('num2') ? Input::get('num2') : NULL ; - if($num1 !== NULL && $num2 !== NULL){ - $answer = $add->calculate($num1,$num2); - } + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + $answer = $add->calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } return view('add', array('answer' => $answer)); } @@ -31,11 +34,14 @@ public function minus(){ $minus = new Minus(); $answer = null; - $num1 = Input::has('num1') ? Input::get('num1') : NULL ; - $num2 = Input::has('num2') ? Input::get('num2') : NULL ; - if($num1 !== NULL && $num2 !== NULL){ - $answer = $minus->calculate($num1,$num2); - } + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + $answer = $minus->calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } return view('minus', array('answer' => $answer)); } @@ -45,11 +51,14 @@ public function multiply(){ $multiply = new Multiply(); $answer = null; - $num1 = Input::has('num1') ? Input::get('num1') : NULL ; - $num2 = Input::has('num2') ? Input::get('num2') : NULL ; - if($num1 !== NULL && $num2 !== NULL){ - $answer = $multiply->calculate($num1,$num2); - } + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + $answer = $multiply->calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } return view('multiply', array('answer' => $answer)); } @@ -59,11 +68,17 @@ public function divide(){ $divide = new Divide(); $answer = null; - $num1 = Input::has('num1') ? Input::get('num1') : NULL ; - $num2 = Input::has('num2') ? Input::get('num2') : NULL ; - if($num1 !== NULL && $num2 !== NULL && $num2 != 0){ - $answer = $divide->calculate($num1,$num2); - } + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + if(Input::get('num2') != 0) + $answer = $divide->calculate(Input::get('num1'),Input::get('num2')); + else + $answer = "Cannot divided by zero"; + } + else{ + $answer = "Numbers are required"; + } + } return view('divide', array('answer' => $answer)); } diff --git a/tests/Feature/AddControllerTest.php b/tests/Feature/AddControllerTest.php index 9bf9d85..dcf0912 100644 --- a/tests/Feature/AddControllerTest.php +++ b/tests/Feature/AddControllerTest.php @@ -16,10 +16,6 @@ public function testAddMainViewDisplay() $response->assertStatus(200) ->assertSee('Add (บวก)') - ->assertSee('+') - ->assertSee('-') - ->assertSee('x') - ->assertSee('/') ; } @@ -28,17 +24,16 @@ public function testAnswerShouldDisplay() $response = $this->post('/add', ['num1' => 1, 'num2' => 2]); $response->assertStatus(200) - ->assertSee('name="num1" value="3" readonly') - # ->assertSee('3') + ->assertSee('3') ; } public function testAnswerShouldReceiveFormAnotherView() { - $response = $this->post('/add', ['num1' => 5]); + $response = $this->post('/add', ['num1' => 5, 'num2' => 0]); $response->assertStatus(200) - ->assertSee('name="num1" value="5" readonly') + ->assertSee('5') ; } @@ -62,22 +57,22 @@ public function testFloatShouldBeAdded() $response = $this->post('/add', ['num1' => 3.2, 'num2' => 1.8]); $response->assertStatus(200) - ->assertSee(5) + ->assertSee('5') ; $response = $this->post('/add', ['num1' => 3, 'num2' => 1.0]); $response->assertStatus(200) - ->assertSee(4) + ->assertSee('4') ; $response = $this->post('/add', ['num1' => 3.0, 'num2' => 1]); $response->assertStatus(200) - ->assertSee(4) + ->assertSee('4') ; $response = $this->post('/add', ['num1' => 0.0, 'num2' => 0.0]); $response->assertStatus(200) - ->assertSee(0) + ->assertSee('0') ; } @@ -85,12 +80,12 @@ public function testNegativeShouldBeAdd() { $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); $response->assertStatus(200) - ->assertSee(0) + ->assertSee('0') ; $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); $response->assertStatus(200) - ->assertSee(0) + ->assertSee('0') ; } diff --git a/tests/Feature/DivideControllerTest.php b/tests/Feature/DivideControllerTest.php new file mode 100644 index 0000000..b10da5e --- /dev/null +++ b/tests/Feature/DivideControllerTest.php @@ -0,0 +1,97 @@ +get('/divide'); + + $response->assertStatus(200) + ->assertSee('Divide (หาร)') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/divide', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('0.5') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/divide', ['num1' => 5, 'num2' => 5]); + + $response->assertStatus(200) + ->assertSee('1') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/divide', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/divide', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeDivided() + { + $response = $this->post('/divide', ['num1' => 3, 'num2' => 1.5]); + + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/divide', ['num1' => 1, 'num2' => 0.5]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/divide', ['num1' => 3.0, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee('1.5') + ; + + $response = $this->post('/divide', ['num1' => 10, 'num2' => 2.5]); + $response->assertStatus(200) + ->assertSee('4') + ; + } + + public function testNegativeShouldBeDivided() + { + $response = $this->post('/divide', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('1') + ; + + $response = $this->post('/divide', ['num1' => 2, 'num2' => -4]); + $response->assertStatus(200) + ->assertSee('-0.5') + ; + } + + public function testZeroShouldNotBeDivider(){ + $response = $this->post('/divide', ['num1' => 40, 'num2' => 0]); + $response->assertStatus(200) + ->assertSee('Cannot divided by zero') + ; + } +} diff --git a/tests/Feature/MinusControllerTest.php b/tests/Feature/MinusControllerTest.php index ed99826..e9aa978 100644 --- a/tests/Feature/MinusControllerTest.php +++ b/tests/Feature/MinusControllerTest.php @@ -16,12 +16,8 @@ public function testMinusMainViewDisplay() $response->assertStatus(200) ->assertSee('Minus (ลบ)') - ->assertSee('=') - ->assertSee('+') - ->assertSee('-') - ->assertSee('x') - ->assertSee('/') ; + } public function testMinusAnswerShouldDisplay() @@ -29,17 +25,16 @@ public function testMinusAnswerShouldDisplay() $response = $this->post('/minus', ['num1' => 1, 'num2' => 1]); $response->assertStatus(200) - ->assertSee('name="num1" value="2" readonly') - # ->assertSee('3') + ->assertSee('0') ; } public function testAnswerShouldReceiveFormAnotherView() { - $response = $this->post('/minus', ['num1' => 0]); + $response = $this->post('/minus', ['num1' => 0, 'num2' => 0]); $response->assertStatus(200) - ->assertSee('name="num1" value="0" readonly') + ->assertSee('0') ; } @@ -65,22 +60,22 @@ public function testFloatShouldBeMinus() { $response = $this->post('/minus', ['num1' => 3.2, 'num2' => 1.2]); $response->assertStatus(200) - ->assertSee(2) + ->assertSee('2') ; $response = $this->post('/minus', ['num1' => 3, 'num2' => 1.0]); $response->assertStatus(200) - ->assertSee(2) + ->assertSee('2') ; $response = $this->post('/minus', ['num1' => 3.0, 'num2' => 1]); $response->assertStatus(200) - ->assertSee(2) + ->assertSee('2') ; $response = $this->post('/minus', ['num1' => 0.0, 'num2' => 0.0]); $response->assertStatus(200) - ->assertSee(0) + ->assertSee('0') ; } @@ -88,17 +83,17 @@ public function testNegativeShouldBeMinus() { $response = $this->post('/minus', ['num1' => 1, 'num2' => -1]); $response->assertStatus(200) - ->assertSee(2) + ->assertSee('2') ; $response = $this->post('/minus', ['num1' => -1, 'num2' => -1]); $response->assertStatus(200) - ->assertSee(0) + ->assertSee('0') ; $response = $this->post('/minus', ['num1' => -1, 'num2' => 2]); $response->assertStatus(200) - ->assertSee(-3) + ->assertSee('-3') ; } } diff --git a/tests/Feature/MultiplyControllerTest.php b/tests/Feature/MultiplyControllerTest.php new file mode 100644 index 0000000..a953d0a --- /dev/null +++ b/tests/Feature/MultiplyControllerTest.php @@ -0,0 +1,90 @@ +get('/multiply'); + + $response->assertStatus(200) + ->assertSee('Multiply (คูณ)') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/multiply', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('2') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/multiply', ['num1' => 5, 'num2' => 0]); + + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/multiply', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/multiply', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeMultiplied() + { + $response = $this->post('/multiply', ['num1' => 2.0, 'num2' => 2.2]); + + $response->assertStatus(200) + ->assertSee('4.4') + ; + + $response = $this->post('/multiply', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee('3') + ; + + $response = $this->post('/multiply', ['num1' => 3.0, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee('6') + ; + + $response = $this->post('/multiply', ['num1' => 1.5, 'num2' => 10]); + $response->assertStatus(200) + ->assertSee('15') + ; + } + + public function testNegativeShouldBeMultiplied() + { + $response = $this->post('/multiply', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('1') + ; + + $response = $this->post('/multiply', ['num1' => 2, 'num2' => -4]); + $response->assertStatus(200) + ->assertSee('-8') + ; + } +}