Permalink
Browse files

Add expired item processing

  • Loading branch information...
rickerbh committed Sep 22, 2016
1 parent ae3a6b7 commit f12c0174a27e43484cc3bd23b077cc087509b94b
Showing with 21 additions and 0 deletions.
  1. +7 −0 GildedRose/ItemBehaviour.swift
  2. +14 −0 GildedRoseTests/ItemBehaviourTests.swift
@@ -30,4 +30,11 @@ class ItemBehaviour {
item.sellIn = item.sellIn - 1
}
+ func processExpiredItem(_ item: Item) {
+ guard item.sellIn < 0 else {
+ return
+ }
+ setQuality(item, quality: item.quality - 1)
+ }
+
}
@@ -40,4 +40,18 @@ class ItemBehaviourTests: XCTestCase {
XCTAssertEqual(9, item.sellIn)
}
+ func testExpiredItemProcessingDecrementsAgain() {
+ let item = Item(name: "+5 Dexterity Vest", sellIn: -1, quality: 20)
+ let behaviour = ItemBehaviour()
+ behaviour.processExpiredItem(item)
+ XCTAssertEqual(19, item.quality)
+ }
+
+ func testNonExpiredItemUnaffectedByProcessingExpired() {
+ let item = Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20)
+ let behaviour = ItemBehaviour()
+ behaviour.processExpiredItem(item)
+ XCTAssertEqual(20, item.quality)
+ }
+
}

0 comments on commit f12c017

Please sign in to comment.