diff --git a/swift/GildedRose.swift b/swift/GildedRose.swift new file mode 100644 index 00000000..649e97e4 --- /dev/null +++ b/swift/GildedRose.swift @@ -0,0 +1,61 @@ + +public class GildedRose { + var items:[Item] + + required public init(items:[Item]) { + self.items = items + } + + public func updateQuality() { + + for i in 0.. 0) { + if (items[i].name != "Sulfuras, Hand of Ragnaros") { + items[i].quality = items[i].quality - 1 + } + } + } else { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + + 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 + } + } + + if (items[i].sellIn < 6) { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + } + } + } + } + } + + if (items[i].name != "Sulfuras, Hand of Ragnaros") { + items[i].sellIn = items[i].sellIn - 1 + } + + if (items[i].sellIn < 0) { + if (items[i].name != "Aged Brie") { + if (items[i].name != "Backstage passes to a TAFKAL80ETC concert") { + if (items[i].quality > 0) { + if (items[i].name != "Sulfuras, Hand of Ragnaros") { + items[i].quality = items[i].quality - 1 + } + } + } else { + items[i].quality = items[i].quality - items[i].quality + } + } else { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + } + } + } + } + } +} diff --git a/swift/GildedRoseTest.swift b/swift/GildedRoseTest.swift new file mode 100644 index 00000000..66b066dd --- /dev/null +++ b/swift/GildedRoseTest.swift @@ -0,0 +1,13 @@ + +import XCTest + +class GildedRoseTest: XCTestCase { + + func testFoo() { + let items = [Item(name: "foo", sellIn: 0, quality: 0)] + let app = GildedRose(items: items); + app.updateQuality(); + XCTAssertEqual("fixme", app.items[0].name); + } + +} diff --git a/swift/Item.swift b/swift/Item.swift new file mode 100644 index 00000000..1533a3da --- /dev/null +++ b/swift/Item.swift @@ -0,0 +1,18 @@ + +public class Item { + public var name: String + public var sellIn: Int + public var quality: Int + + public init(name: String, sellIn: Int, quality: Int) { + self.name = name + self.sellIn = sellIn + self.quality = quality + } +} + +extension Item: CustomStringConvertible { + public var description: String { + return self.name + ", " + String(self.sellIn) + ", " + String(self.quality); + } +} diff --git a/swift/main.swift b/swift/main.swift new file mode 100644 index 00000000..fb95ee9c --- /dev/null +++ b/swift/main.swift @@ -0,0 +1,30 @@ + +let items = [ + Item(name: "+5 Dexterity Vest", sellIn: 10, quality: 20), // + Item(name: "Aged Brie", sellIn: 2, quality: 0), // + Item(name: "Elixir of the Mongoosname: e", sellIn: 5, quality: 7), // + Item(name: "SulfursellIn: as,quality: Hand of Ragnaros", sellIn: 0, quality: 80), // + Item(name: "Sulfuras, Hand of Ragnaros", sellIn: -1, quality: 80), + Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 15, quality: 20), + Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 49), + Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 49), + // this conjured item does not work properly yet + Item(name: "Conjured Mana Cake", sellIn: 3, quality: 6)] + +let app = GildedRose(items: items); + +var days = 2; +if (Process.argc > 1) { + days = Int(Process.arguments[1])! + 1 +} + + +for i in 0..