Permalink
Browse files

Factor out incrementing quality

  • Loading branch information...
rickerbh committed Sep 22, 2016
1 parent 1aa2262 commit 685e521451764d339d48849d5a9d11b02df01da5
Showing with 28 additions and 15 deletions.
  1. +13 −12 GildedRose/GildedRose.swift
  2. +15 −3 GildedRoseTests/GildedRoseTests.swift
@@ -9,23 +9,19 @@ public class GildedRose {
public func updateQuality() {
for i in 0..<items.count {
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") {
decrementQuality(items[i])
} else {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1
incrementQuality(items[i])
if (items[i].name == "Backstage passes to a TAFKAL80ETC concert") {
if (items[i].sellIn < 11) {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1
}
incrementQuality(items[i])
}
if (items[i].sellIn < 6) {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1
}
incrementQuality(items[i])
}
}
}
@@ -41,9 +37,7 @@ public class GildedRose {
items[i].quality = items[i].quality - items[i].quality
}
} else {
if (items[i].quality < 50) {
items[i].quality = items[i].quality + 1
}
incrementQuality(items[i])
}
}
}
@@ -59,6 +53,13 @@ public class GildedRose {
item.quality = item.quality - 1
}
internal func incrementQuality(_ item: Item) {
guard item.quality < 50 else {
return
}
item.quality = item.quality + 1
}
internal func decrementSellDate(_ item: Item) {
guard item.name != "Sulfuras, Hand of Ragnaros" else {
return
@@ -76,12 +76,10 @@ class GildedRoseTests: XCTestCase {
}
func testQualityNeverLessThan0() {
let vest = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 1)
let vest = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 0)
let app = GildedRose(items: [])
app.decrementQuality(vest)
XCTAssertEqual(0, vest.quality)
app.decrementQuality(vest)
XCTAssertEqual(0, vest.quality)
}
func testSulfurasQualityNeverDecrements() {
@@ -91,4 +89,18 @@ class GildedRoseTests: XCTestCase {
XCTAssertEqual(80, sulfuras.quality)
}
func testQualityIsIncremented() {
let brie = Item(name: "Aged Brie", sellIn: 2, quality: 0)
let app = GildedRose(items: [])
app.incrementQuality(brie)
XCTAssertEqual(1, brie.quality)
}
func testQualityNeverGoesAbove50() {
let brie = Item(name: "Aged Brie", sellIn: 2, quality: 50)
let app = GildedRose(items: [])
app.incrementQuality(brie)
XCTAssertEqual(50, brie.quality)
}
}

0 comments on commit 685e521

Please sign in to comment.