Skip to content
Permalink
Browse files

Extract decrement date

Move it to the base itembehaviour class.
Overide behaviour for sulfuras.
  • Loading branch information
rickerbh committed Sep 22, 2016
1 parent 3809fe5 commit ae3a6b704a124f697778e1409d11d03d525a49de
@@ -10,6 +10,7 @@ public class GildedRose {
for i in 0..<items.count {
let itemBehaviour = BehaviourFactory.getBehaviour(items[i])
itemBehaviour.updateQualityPreDateChange(items[i])
itemBehaviour.decrementSellDate(items[i])

if items[i].sellIn < 0 {
if items[i].name == "Aged Brie" {
@@ -38,13 +39,6 @@ public class GildedRose {
item.quality = item.quality + 1
}

internal func decrementSellDate(_ item: Item) {
guard item.name != "Sulfuras, Hand of Ragnaros" else {
return
}
item.sellIn = item.sellIn - 1
}

internal func processExpiredItem(_ item: Item) {
guard item.sellIn < 0 else {
return
@@ -26,4 +26,8 @@ class ItemBehaviour {
item.quality = quality
}

func decrementSellDate(_ item: Item) {
item.sellIn = item.sellIn - 1
}

}
@@ -12,4 +12,9 @@ class SulfurasBehaviour: ItemBehaviour {
override func updateQualityPreDateChange(_ item: Item) {
return
}

override func decrementSellDate(_ item: Item) {
return
}

}
@@ -56,20 +56,6 @@ class GildedRoseTests: XCTestCase {
}
}

func testSellDateDecrements() {
let vest = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20)
let app = GildedRose(items: [])
app.decrementSellDate(vest)
XCTAssertEqual(9, vest.sellIn)
}

func testSulfurasSellDateNeverDecrements() {
let sulfuras = Item(name: "Sulfuras, Hand of Ragnaros", sellIn: -1, quality: 80)
let app = GildedRose(items: [])
app.decrementSellDate(sulfuras)
XCTAssertEqual(-1, sulfuras.sellIn)
}

func testQualityIsDecremented() {
let vest = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20)
let app = GildedRose(items: [])
@@ -33,4 +33,11 @@ class ItemBehaviourTests: XCTestCase {
XCTAssertEqual(0, vest.quality)
}

func testDecrementDay() {
let item = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20)
let behaviour = ItemBehaviour()
behaviour.decrementSellDate(item)
XCTAssertEqual(9, item.sellIn)
}

}
@@ -15,4 +15,12 @@ class SulfurasBehaviourTests: XCTestCase {
behaviour.updateQualityPreDateChange(item)
XCTAssertEqual(80, item.quality)
}

func testDecrementDayDoesntChangeDate() {
let item = Item(name: "Sulfuras, Hand of Ragnaros", sellIn: 15, quality: 80)
let behaviour = SulfurasBehaviour()
behaviour.decrementSellDate(item)
XCTAssertEqual(15, item.sellIn)
}

}

0 comments on commit ae3a6b7

Please sign in to comment.
You can’t perform that action at this time.