Skip to content

Commit

Permalink
test JuiceMaker test_과일쥬스를_만들고_남은과일의_개수가_올바른가() 케이스 추가 #1
Browse files Browse the repository at this point in the history
- FruitStore 타입 변경 (Struct -> Class)
  • Loading branch information
김정상 committed Feb 16, 2022
1 parent 4d80b27 commit a5ab11f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions JuiceMaker/JuiceMaker/Model/FruitStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension FruitStoreError: LocalizedError {
}

/// 과일 저장소 타입
struct FruitStore {
class FruitStore {
private(set) var inventory = [FruitType: Int]()

init(initialFruitCount: Int = 10) {
Expand All @@ -29,7 +29,7 @@ struct FruitStore {
}
}

mutating func use(of fruitTypes: [FruitType: Int]) -> Result<Void, FruitStoreError> {
func use(of fruitTypes: [FruitType: Int]) -> Result<Void, FruitStoreError> {
let checkedInventory = checkInventory(of: fruitTypes)
switch checkedInventory {
case .success():
Expand All @@ -40,7 +40,7 @@ struct FruitStore {
}
}

mutating func changeFruitCount(of fruit: FruitType, count: Int) {
func changeFruitCount(of fruit: FruitType, count: Int) {
guard count > 0 else {
return
}
Expand Down
25 changes: 25 additions & 0 deletions JuiceMaker/JuiceMakerTests/JuiceMakerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,29 @@ class JuiceMakerTests: XCTestCase {
XCTSuccess()
}
}

func test_과일쥬스를_만들고_남은과일의_개수가_올바른가() {
// given
let fruitStore = FruitStore(initialFruitCount: 10)
var juiceMaker = JuiceMaker(fruitStore: fruitStore)
let input = MockJuice(items: [.banana: 5])
let expected: [FruitType: Int] = [
.strawberry: 10,
.banana: 5,
.pineapple: 10,
.kiwi: 10,
.mango: 10
]

// when
let writeResult = juiceMaker.make(with: input)

// then
switch writeResult {
case .success():
XCTAssertEqual(fruitStore.inventory, expected)
case .failure(_):
XCTFail()
}
}
}

0 comments on commit a5ab11f

Please sign in to comment.