mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
a - Apply SwiftFormat
This commit is contained in:
parent
b57ae7007d
commit
31afd92d95
@ -7,17 +7,21 @@ let package = Package(
|
|||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
name: "GildedRose",
|
name: "GildedRose",
|
||||||
targets: ["GildedRose"]),
|
targets: ["GildedRose"]
|
||||||
|
),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "GildedRose",
|
name: "GildedRose",
|
||||||
dependencies: []),
|
dependencies: []
|
||||||
|
),
|
||||||
.target(
|
.target(
|
||||||
name: "GildedRoseApp",
|
name: "GildedRoseApp",
|
||||||
dependencies: ["GildedRose"]),
|
dependencies: ["GildedRose"]
|
||||||
|
),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "GildedRoseTests",
|
name: "GildedRoseTests",
|
||||||
dependencies: ["GildedRose"]),
|
dependencies: ["GildedRose"]
|
||||||
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
public class GildedRose {
|
public class GildedRose {
|
||||||
var items: [Item]
|
var items: [Item]
|
||||||
|
|
||||||
public init(items: [Item]) {
|
public init(items: [Item]) {
|
||||||
self.items = items
|
self.items = items
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateQuality() {
|
public func updateQuality() {
|
||||||
for i in 0 ..< items.count {
|
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" {
|
||||||
if items[i].quality > 0 {
|
if items[i].quality > 0 {
|
||||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
||||||
items[i].quality = items[i].quality - 1
|
items[i].quality = items[i].quality - 1
|
||||||
@ -16,14 +16,14 @@ public class GildedRose {
|
|||||||
} else {
|
} else {
|
||||||
if items[i].quality < 50 {
|
if items[i].quality < 50 {
|
||||||
items[i].quality = items[i].quality + 1
|
items[i].quality = items[i].quality + 1
|
||||||
|
|
||||||
if items[i].name == "Backstage passes to a TAFKAL80ETC concert" {
|
if items[i].name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
if items[i].sellIn < 11 {
|
if items[i].sellIn < 11 {
|
||||||
if items[i].quality < 50 {
|
if items[i].quality < 50 {
|
||||||
items[i].quality = items[i].quality + 1
|
items[i].quality = items[i].quality + 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if items[i].sellIn < 6 {
|
if items[i].sellIn < 6 {
|
||||||
if items[i].quality < 50 {
|
if items[i].quality < 50 {
|
||||||
items[i].quality = items[i].quality + 1
|
items[i].quality = items[i].quality + 1
|
||||||
@ -32,11 +32,11 @@ public class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
||||||
items[i].sellIn = items[i].sellIn - 1
|
items[i].sellIn = items[i].sellIn - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if items[i].sellIn < 0 {
|
if items[i].sellIn < 0 {
|
||||||
if items[i].name != "Aged Brie" {
|
if items[i].name != "Aged Brie" {
|
||||||
if items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
if items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ public class Item {
|
|||||||
public var name: String
|
public var name: String
|
||||||
public var sellIn: Int
|
public var sellIn: Int
|
||||||
public var quality: Int
|
public var quality: Int
|
||||||
|
|
||||||
public init(name: String, sellIn: Int, quality: Int) {
|
public init(name: String, sellIn: Int, quality: Int) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.sellIn = sellIn
|
self.sellIn = sellIn
|
||||||
@ -12,6 +12,6 @@ public class Item {
|
|||||||
|
|
||||||
extension Item: CustomStringConvertible {
|
extension Item: CustomStringConvertible {
|
||||||
public var description: String {
|
public var description: String {
|
||||||
name + ", " + String(sellIn) + ", " + String(quality);
|
name + ", " + String(sellIn) + ", " + String(quality)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,21 +10,22 @@ let items = [
|
|||||||
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 49),
|
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 49),
|
||||||
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 49),
|
Item(name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 49),
|
||||||
// this conjured item does not work properly yet
|
// this conjured item does not work properly yet
|
||||||
Item(name: "Conjured Mana Cake", sellIn: 3, quality: 6)]
|
Item(name: "Conjured Mana Cake", sellIn: 3, quality: 6),
|
||||||
|
]
|
||||||
|
|
||||||
let app = GildedRose(items: items);
|
let app = GildedRose(items: items)
|
||||||
|
|
||||||
var days = 2;
|
var days = 2
|
||||||
if CommandLine.argc > 1 {
|
if CommandLine.argc > 1 {
|
||||||
days = Int(CommandLine.arguments[1])! + 1
|
days = Int(CommandLine.arguments[1])! + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..<days {
|
for i in 0 ..< days {
|
||||||
print("-------- day \(i) --------");
|
print("-------- day \(i) --------")
|
||||||
print("name, sellIn, quality");
|
print("name, sellIn, quality")
|
||||||
for item in items {
|
for item in items {
|
||||||
print(item);
|
print(item)
|
||||||
}
|
}
|
||||||
print("");
|
print("")
|
||||||
app.updateQuality();
|
app.updateQuality()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
class GildedRoseTests: XCTestCase {
|
class GildedRoseTests: XCTestCase {
|
||||||
|
|
||||||
func testFoo() throws {
|
func testFoo() throws {
|
||||||
let items = [Item(name: "foo", sellIn: 0, quality: 0)]
|
let items = [Item(name: "foo", sellIn: 0, quality: 0)]
|
||||||
let app = GildedRose(items: items)
|
let app = GildedRose(items: items)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user