-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- FruitStore checkInventory 오류 수정 - FruitStore calculateUsableInventory 함수 분리
- Loading branch information
김정상
committed
Feb 15, 2022
1 parent
40c67e5
commit 2d6f417
Showing
3 changed files
with
227 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// FruitStoreTests.swift | ||
// FruitStoreTests | ||
// | ||
// Created by 김정상 on 2022/02/16. | ||
// | ||
|
||
import XCTest | ||
@testable import JuiceMaker | ||
|
||
class FruitStoreTests: XCTestCase { | ||
|
||
// MARK: - Property | ||
|
||
private var fruitStore: FruitStore? | ||
|
||
|
||
// MARK: - Overrides | ||
|
||
override func setUpWithError() throws { | ||
try super.setUpWithError() | ||
fruitStore = FruitStore() | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
try super.tearDownWithError() | ||
fruitStore = nil | ||
} | ||
|
||
|
||
// MARK: - Test codes | ||
|
||
func test_인벤토리보다_적은과일을_사용했을때_성공을_반환하는가() { | ||
// given | ||
guard var fruitStore = fruitStore else { | ||
XCTFail() | ||
return | ||
} | ||
let input: [FruitType: Int] = [ | ||
.banana: 5, | ||
.strawberry: 5 | ||
] | ||
let expected: [FruitType: Int] = [ | ||
.strawberry: 5, | ||
.banana: 5, | ||
.pineapple: 10, | ||
.kiwi: 10, | ||
.mango: 10 | ||
] | ||
|
||
// when | ||
let writeResult = fruitStore.use(of: input) | ||
|
||
// then | ||
switch writeResult { | ||
case .success(_): | ||
XCTAssertEqual(fruitStore.inventory, expected) | ||
case .failure(let error): | ||
XCTFail(error.localizedDescription) | ||
} | ||
} | ||
|
||
func test_인벤토리보다_많은과일을_사용했을때_실패을_반환하는가() { | ||
// given | ||
guard var fruitStore = fruitStore else { | ||
XCTFail() | ||
return | ||
} | ||
let input: [FruitType: Int] = [ | ||
.banana: 5, | ||
.strawberry: 15 | ||
] | ||
let expected = FruitStoreError.notEnoughFruits | ||
|
||
// when | ||
let writeResult = fruitStore.use(of: input) | ||
|
||
// then | ||
switch writeResult { | ||
case .success(_): | ||
XCTFail() | ||
case .failure(let error): | ||
XCTAssertEqual(expected, error) | ||
} | ||
} | ||
|
||
} |