mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
Conjuredに対して「販売するための残り日数が無くなると、Quality値は2小さくなります。」仕様が漏れていたので追加
This commit is contained in:
parent
6b85d52e6f
commit
9884e30e01
@ -38,10 +38,11 @@ final class GildedRose
|
|||||||
[商品:Conjured]
|
[商品:Conjured]
|
||||||
・引数のsell_inを-1する
|
・引数のsell_inを-1する
|
||||||
・引数のqualityを-2する
|
・引数のqualityを-2する
|
||||||
|
・sell_inが0未満の場合、さらにquality-2する
|
||||||
[その他商品]
|
[その他商品]
|
||||||
・引数のsell_inを-1する
|
・引数のsell_inを-1する
|
||||||
・引数のqualityを-1する
|
・引数のqualityを-1する
|
||||||
・sell_inが0未満の場合、さらにquality-1する ★仕様書に記載なかったがコード上はこのようになっている
|
・sell_inが0未満の場合、さらにquality-1する
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,9 +120,12 @@ final class GildedRose
|
|||||||
private function conjured(): void
|
private function conjured(): void
|
||||||
{
|
{
|
||||||
$this->calcSellInSubtraction();
|
$this->calcSellInSubtraction();
|
||||||
// 新たな関数は作成せず減算処理を2回実行する
|
$this->calcQualityDoubleSubtraction();
|
||||||
$this->calcQualitySubtraction();
|
|
||||||
$this->calcQualitySubtraction();
|
// sell_inが0未満の場合、sell_inを再減算する
|
||||||
|
if ($this->item->sell_in < 0) {
|
||||||
|
$this->calcQualityDoubleSubtraction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,4 +171,20 @@ final class GildedRose
|
|||||||
--$this->item->quality;
|
--$this->item->quality;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qualityを2倍の減算を行う
|
||||||
|
*/
|
||||||
|
private function calcQualityDoubleSubtraction(): void
|
||||||
|
{
|
||||||
|
// 1以上の場合計算
|
||||||
|
if ($this->item->quality >= 1) {
|
||||||
|
$this->item->quality -=2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// qualityが0未満の場合、0を設定
|
||||||
|
if ($this->item->quality < 0) {
|
||||||
|
$this->item->quality = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -284,6 +284,62 @@ class GildedRoseTest extends TestCase
|
|||||||
$this->assertSame(0, $items[0]->quality);
|
$this->assertSame(0, $items[0]->quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conjured:sell_inが0以下、qualityが50未満
|
||||||
|
* 期待値:sell_inが-1、qualityが-4
|
||||||
|
*/
|
||||||
|
public function testConjuredSellIn0OrLess(): void
|
||||||
|
{
|
||||||
|
$items = [new Item('Conjured Mana Cake', 0, 10)];
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertSame('Conjured Mana Cake', $items[0]->name);
|
||||||
|
$this->assertSame(-1, $items[0]->sell_in);
|
||||||
|
$this->assertSame(6, $items[0]->quality);
|
||||||
|
|
||||||
|
$items = [new Item('Conjured Mana Cake', -1, 10)];
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertSame('Conjured Mana Cake', $items[0]->name);
|
||||||
|
$this->assertSame(-2, $items[0]->sell_in);
|
||||||
|
$this->assertSame(6, $items[0]->quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conjured:sell_inが0以下、qualityが2以下
|
||||||
|
* 期待値:sell_inが-1、qualityを減算、0が下限
|
||||||
|
*/
|
||||||
|
public function testConjuredSellIn0OrLessAndQuality2OrLess(): void
|
||||||
|
{
|
||||||
|
$items = [new Item('Conjured Mana Cake', 0, 2)];
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertSame('Conjured Mana Cake', $items[0]->name);
|
||||||
|
$this->assertSame(-1, $items[0]->sell_in);
|
||||||
|
$this->assertSame(0, $items[0]->quality);
|
||||||
|
|
||||||
|
$items = [new Item('Conjured Mana Cake', 0, 1)];
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertSame('Conjured Mana Cake', $items[0]->name);
|
||||||
|
$this->assertSame(-1, $items[0]->sell_in);
|
||||||
|
$this->assertSame(0, $items[0]->quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conjured:sell_inが0、qualityが0
|
||||||
|
* 期待値:sell_inが-1、qualityは変更なし
|
||||||
|
*/
|
||||||
|
public function testConjuredSellIn0AndQuality0(): void
|
||||||
|
{
|
||||||
|
$items = [new Item('Conjured Mana Cake', 0, 0)];
|
||||||
|
$gildedRose = new GildedRose($items);
|
||||||
|
$gildedRose->updateQuality();
|
||||||
|
$this->assertSame('Conjured Mana Cake', $items[0]->name);
|
||||||
|
$this->assertSame(-1, $items[0]->sell_in);
|
||||||
|
$this->assertSame(0, $items[0]->quality);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 複数商品
|
* 複数商品
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user