mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Added base rules
This commit is contained in:
parent
ef2d3a6f91
commit
e1e1abeadf
45
swift/Tests/GildedRoseTests/BaseRules.swift
Normal file
45
swift/Tests/GildedRoseTests/BaseRules.swift
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// BaseRules.swift
|
||||
// GildedRose
|
||||
//
|
||||
// Created by Lucas van Dongen on 23/11/2020.
|
||||
//
|
||||
|
||||
@testable import GildedRose
|
||||
import XCTest
|
||||
|
||||
class BaseRules: XCTestCase {
|
||||
private let testItem = Item(name: "Test Item", sellIn: 3, quality: 5)
|
||||
|
||||
//- All items have a SellIn value which denotes the number of days we have to sell the item
|
||||
func testSellInTest() {
|
||||
let itemMirror = Mirror(reflecting: testItem)
|
||||
let hasSellIn = itemMirror.children.contains { (child: (label: String?, _: Any)) -> Bool in
|
||||
child.label == "sellIn"
|
||||
}
|
||||
|
||||
XCTAssertTrue(hasSellIn, "`sellIn` was not a member of `Item`")
|
||||
}
|
||||
|
||||
//- All items have a Quality value which denotes how valuable the item is
|
||||
func testQualityValue() {
|
||||
let itemMirror = Mirror(reflecting: testItem)
|
||||
let hasSellIn = itemMirror.children.contains { (child: (label: String?, _: Any)) -> Bool in
|
||||
child.label == "quality"
|
||||
}
|
||||
|
||||
XCTAssertTrue(hasSellIn, "`quality` was not a member of `Item`")
|
||||
}
|
||||
|
||||
//- At the end of each day our system lowers both values for every item
|
||||
func testLowerValueEveryItem() {
|
||||
let initialSellIn = testItem.sellIn
|
||||
let initialQuality = testItem.quality
|
||||
|
||||
let system = GildedRose(items: [testItem])
|
||||
system.updateQuality()
|
||||
|
||||
XCTAssertLessThan(system.items.first!.sellIn, initialSellIn)
|
||||
XCTAssertLessThan(system.items.first!.quality, initialQuality)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user