From a3e2d56a24328fa2e9e2c7ff27e45a21a727bbd9 Mon Sep 17 00:00:00 2001 From: bestaff-hirakawa Date: Sun, 7 Aug 2022 03:10:30 +0900 Subject: [PATCH] =?UTF-8?q?Sulfuras=E3=81=AE=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/src/GildedRose.php | 13 +++++++++++++ php/tests/GildedRoseTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/php/src/GildedRose.php b/php/src/GildedRose.php index 1dcba599..608ede3b 100644 --- a/php/src/GildedRose.php +++ b/php/src/GildedRose.php @@ -27,6 +27,8 @@ final class GildedRose ・引数のsell_inを-1する ・計算後sell_inが0未満の場合、quality+2する ・計算後sell_inが0以上の場合、quality+1する + [商品:Sulfuras] + ・sell_in、qualityどちらも変更しない */ /** @@ -38,6 +40,9 @@ final class GildedRose if ($this->item->name === 'Aged Brie') { // 商品:Aged Brieの処理 $this->agedBrie(); + } elseif ($this->item->name === 'Sulfuras, Hand of Ragnaros') { + // 商品:Sulfurasの処理 + $this->sulfuras(); } } } @@ -56,6 +61,14 @@ final class GildedRose } } + /** + * 商品:Sulfuras計算処理 + */ + private function sulfuras(): void + { + // 何もしない + } + /** * sell_inの減算を行う */ diff --git a/php/tests/GildedRoseTest.php b/php/tests/GildedRoseTest.php index d38c3f01..0be1cbc3 100644 --- a/php/tests/GildedRoseTest.php +++ b/php/tests/GildedRoseTest.php @@ -67,6 +67,39 @@ class GildedRoseTest extends TestCase $this->assertSame(50, $items[0]->quality); } + /** + * Sulfuras:sell_inが1以上、qualityが80 + * 期待値:sell_in、qualityどちらも変更なし + */ + public function testSulfurasNormal(): void + { + $items = [new Item('Sulfuras, Hand of Ragnaros', 5, 80)]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertSame('Sulfuras, Hand of Ragnaros', $items[0]->name); + $this->assertSame(5, $items[0]->sell_in); + $this->assertSame(80, $items[0]->quality); + } + + /** + * 複数商品 + */ + public function testMixCase(): void + { + $items = [ + new Item('Aged Brie', 5, 10), + new Item('Sulfuras, Hand of Ragnaros', 5, 80), + ]; + $gildedRose = new GildedRose($items); + $gildedRose->updateQuality(); + $this->assertSame('Aged Brie', $items[0]->name); + $this->assertSame(4, $items[0]->sell_in); + $this->assertSame(11, $items[0]->quality); + $this->assertSame('Sulfuras, Hand of Ragnaros', $items[1]->name); + $this->assertSame(5, $items[1]->sell_in); + $this->assertSame(80, $items[1]->quality); + } + // テストエラーの原因が特定できないので後で調査する /* public function testApproveArray()