From 6b85d52e6fe883ac5cd02e8609db4d8756922fae Mon Sep 17 00:00:00 2001 From: bestaff-hirakawa Date: Sun, 7 Aug 2022 03:23:30 +0900 Subject: [PATCH] =?UTF-8?q?Conjured=E5=95=86=E5=93=81=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/src/GildedRose.php | 18 +++++++++++++- php/tests/GildedRoseTest.php | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index 65e6c058..5751a93e 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -35,6 +35,9 @@ final class GildedRose ・計算後sell_inが10未満の場合、さらにquality+1する ・計算後sell_inが5未満の場合、さらにquality+1する ・計算後sell_inが0未満の場合、qualityを0にする + [商品:Conjured] + ・引数のsell_inを-1する + ・引数のqualityを-2する [その他商品] ・引数のsell_inを-1する ・引数のqualityを-1する @@ -56,6 +59,9 @@ final class GildedRose } elseif ($this->item->name === 'Backstage passes to a TAFKAL80ETC concert') { // 商品:Backstage passesの処理 $this->backstagePasses(); + } elseif ($this->item->name === 'Conjured Mana Cake') { + // 商品:Conjuredの処理 + $this->conjured(); } else { // その他商品の処理 $this->others(); @@ -107,6 +113,17 @@ final class GildedRose } } + /** + * 商品:Conjured計算処理 + */ + private function conjured(): void + { + $this->calcSellInSubtraction(); + // 新たな関数は作成せず減算処理を2回実行する + $this->calcQualitySubtraction(); + $this->calcQualitySubtraction(); + } + /** * その他商品 */ @@ -151,4 +168,3 @@ final class GildedRose } } } - diff --git a/php/tests/GildedRoseTest.php b/php/tests/GildedRoseTest.php index 82f1a3a4..7ffe28be 100644 --- a/php/tests/GildedRoseTest.php +++ b/php/tests/GildedRoseTest.php @@ -242,6 +242,48 @@ class GildedRoseTest extends TestCase $this->assertSame(0, $items[0]->quality); } + /** + * Conjured:sell_inが1以上、qualityが50未満 + * 期待値:sell_inが-1、qualityが-2 + */ + public function testConjuredsNormal(): void + { + $items = [new Item('Conjured Mana Cake', 10, 10)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertSame('Conjured Mana Cake', $items[0]->name); + $this->assertSame(9, $items[0]->sell_in); + $this->assertSame(8, $items[0]->quality); + } + + /** + * Conjured:sell_inが1以上、qualityが1 + * 期待値:sell_inが-1、qualityが-1 + */ + public function testConjuredQuality1(): void + { + $items = [new Item('Conjured Mana Cake', 10, 1)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertSame('Conjured Mana Cake', $items[0]->name); + $this->assertSame(9, $items[0]->sell_in); + $this->assertSame(0, $items[0]->quality); + } + + /** + * Conjured:sell_inが1以上、qualityが0 + * 期待値:sell_inが-1、qualityは変更なし + */ + public function testConjuredQuality0(): void + { + $items = [new Item('Conjured Mana Cake', 10, 0)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertSame('Conjured Mana Cake', $items[0]->name); + $this->assertSame(9, $items[0]->sell_in); + $this->assertSame(0, $items[0]->quality); + } + /** * 複数商品 */ @@ -252,6 +294,7 @@ class GildedRoseTest extends TestCase new Item('Sulfuras, Hand of Ragnaros', 5, 80), new Item('Backstage passes to a TAFKAL80ETC concert', 5, 10), new Item('Foo', 5, 10), + new Item('Conjured Mana Cake', 5, 10), ]; $gildedRose = new GildedRose($items); $gildedRose->updateQuality(); @@ -267,6 +310,9 @@ class GildedRoseTest extends TestCase $this->assertSame('Foo', $items[3]->name); $this->assertSame(4, $items[3]->sell_in); $this->assertSame(9, $items[3]->quality); + $this->assertSame('Conjured Mana Cake', $items[4]->name); + $this->assertSame(4, $items[4]->sell_in); + $this->assertSame(8, $items[4]->quality); } // テストエラーの原因が特定できないので後で調査する