mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Backstage passesのリファクタリング
This commit is contained in:
parent
a3e2d56a24
commit
01eb701417
@ -29,6 +29,12 @@ final class GildedRose
|
||||
・計算後sell_inが0以上の場合、quality+1する
|
||||
[商品:Sulfuras]
|
||||
・sell_in、qualityどちらも変更しない
|
||||
[商品:Backstage passes]
|
||||
・引数のsell_inを-1する
|
||||
・引数のqualityを+1する
|
||||
・計算後sell_inが10未満の場合、さらにquality+1する
|
||||
・計算後sell_inが5未満の場合、さらにquality+1する
|
||||
・計算後sell_inが0未満の場合、qualityを0にする
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -43,6 +49,9 @@ final class GildedRose
|
||||
} elseif ($this->item->name === 'Sulfuras, Hand of Ragnaros') {
|
||||
// 商品:Sulfurasの処理
|
||||
$this->sulfuras();
|
||||
} elseif ($this->item->name === 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
// 商品:Backstage passesの処理
|
||||
$this->backstagePasses();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,6 +78,28 @@ final class GildedRose
|
||||
// 何もしない
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品:Backstage passes計算処理
|
||||
*/
|
||||
private function backstagePasses(): void
|
||||
{
|
||||
$this->calcSellInSubtraction();
|
||||
$this->calcQualityAddition();
|
||||
|
||||
// sell_inが10未満の場合、qualityを再加算する
|
||||
if ($this->item->sell_in < 10) {
|
||||
$this->calcQualityAddition();
|
||||
}
|
||||
// sell_inが5未満の場合、qualityを再加算する
|
||||
if ($this->item->sell_in < 5) {
|
||||
$this->calcQualityAddition();
|
||||
}
|
||||
// sell_inが0未満の場合、qualityを0する
|
||||
if ($this->item->sell_in < 0) {
|
||||
$this->item->quality = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sell_inの減算を行う
|
||||
*/
|
||||
|
||||
@ -81,6 +81,118 @@ class GildedRoseTest extends TestCase
|
||||
$this->assertSame(80, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backstage passes:sell_inが11以上、qualityが50未満
|
||||
* 期待値:sell_inが-1、qualityが+1
|
||||
*/
|
||||
public function testBackstagePassesNormal(): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 20, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(19, $items[0]->sell_in);
|
||||
$this->assertSame(21, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 11, 49)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(10, $items[0]->sell_in);
|
||||
$this->assertSame(50, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backstage passes:sell_inが6〜10、qualityが50未満
|
||||
* 期待値:sell_inが-1、qualityが+2
|
||||
*/
|
||||
public function testBackstagePassesSellIn6OrMoreAndSellIn10OrLess(): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 6, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(5, $items[0]->sell_in);
|
||||
$this->assertSame(22, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 10, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(9, $items[0]->sell_in);
|
||||
$this->assertSame(22, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backstage passes:sell_inが1〜5、qualityが50未満
|
||||
* 期待値:sell_inが-1、qualityが+3
|
||||
*/
|
||||
public function testBackstagePassesSellIn1OrMoreAndSellIn5OrLess(): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 1, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(0, $items[0]->sell_in);
|
||||
$this->assertSame(23, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 5, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(4, $items[0]->sell_in);
|
||||
$this->assertSame(23, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backstage passes:sell_inが0以下、qualityが50未満
|
||||
* 期待値:sell_inが-1、qualityが+1
|
||||
*/
|
||||
public function testBackstagePassesSellIn0OrLess(): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 0, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(-1, $items[0]->sell_in);
|
||||
$this->assertSame(0, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', -1, 20)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(-2, $items[0]->sell_in);
|
||||
$this->assertSame(0, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backstage passes:qualityが50
|
||||
* 期待値:sell_inが-1、qualityは変更なし
|
||||
*/
|
||||
public function testBackstagePassesQuality50(): void
|
||||
{
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 11, 50)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(10, $items[0]->sell_in);
|
||||
$this->assertSame(50, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 6, 50)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(5, $items[0]->sell_in);
|
||||
$this->assertSame(50, $items[0]->quality);
|
||||
|
||||
$items = [new Item('Backstage passes to a TAFKAL80ETC concert', 1, 50)];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[0]->name);
|
||||
$this->assertSame(0, $items[0]->sell_in);
|
||||
$this->assertSame(50, $items[0]->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* 複数商品
|
||||
*/
|
||||
@ -89,6 +201,7 @@ class GildedRoseTest extends TestCase
|
||||
$items = [
|
||||
new Item('Aged Brie', 5, 10),
|
||||
new Item('Sulfuras, Hand of Ragnaros', 5, 80),
|
||||
new Item('Backstage passes to a TAFKAL80ETC concert', 5, 10),
|
||||
];
|
||||
$gildedRose = new GildedRose($items);
|
||||
$gildedRose->updateQuality();
|
||||
@ -98,6 +211,9 @@ class GildedRoseTest extends TestCase
|
||||
$this->assertSame('Sulfuras, Hand of Ragnaros', $items[1]->name);
|
||||
$this->assertSame(5, $items[1]->sell_in);
|
||||
$this->assertSame(80, $items[1]->quality);
|
||||
$this->assertSame('Backstage passes to a TAFKAL80ETC concert', $items[2]->name);
|
||||
$this->assertSame(4, $items[2]->sell_in);
|
||||
$this->assertSame(13, $items[2]->quality);
|
||||
}
|
||||
|
||||
// テストエラーの原因が特定できないので後で調査する
|
||||
|
||||
Loading…
Reference in New Issue
Block a user