Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeffie committed Jul 24, 2024
2 parents f9916dc + 9172fd7 commit a1ed483
Show file tree
Hide file tree
Showing 64 changed files with 2,059 additions and 223 deletions.
7 changes: 0 additions & 7 deletions BankManager.swift

This file was deleted.

2 changes: 2 additions & 0 deletions BankManagerConsoleApp/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ disabled_rules:
- trailing_whitespace
- trailing_comma
- class_delegate_protocol
- sorted_imports
- closure_parameter_position

force_unwrapping:
severity: error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
2733E4FA2B5F9FDB00785607 /* LinkedList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2733E4F92B5F9FDB00785607 /* LinkedList.swift */; };
2733E4FC2B5FA00300785607 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2733E4FB2B5FA00300785607 /* Queue.swift */; };
2733E4FD2B5FA11800785607 /* LinkedList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2733E4F92B5F9FDB00785607 /* LinkedList.swift */; };
2733E4FE2B5FA11B00785607 /* Queue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2733E4FB2B5FA00300785607 /* Queue.swift */; };
C7694E7A259C3EC00053667F /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7694E79259C3EC00053667F /* main.swift */; };
C7D65D1B259C8190005510E0 /* BankManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7D65D1A259C8190005510E0 /* BankManager.swift */; };
F447FC3A2B5E8053002A2692 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = F447FC392B5E8053002A2692 /* Node.swift */; };
F46FA2A42B63A46A00787C3F /* BankManagerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FA2A32B63A46A00787C3F /* BankManagerApp.swift */; };
F46FA2A82B66309000787C3F /* ConsoleManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FA2A72B66309000787C3F /* ConsoleManager.swift */; };
F46FA2AA2B6630B200787C3F /* TextInputReadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FA2A92B6630B200787C3F /* TextInputReadable.swift */; };
F46FA2AC2B6630CF00787C3F /* BankManagerAppMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FA2AB2B6630CF00787C3F /* BankManagerAppMenu.swift */; };
F46FA2AE2B6630E300787C3F /* IOError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FA2AD2B6630E300787C3F /* IOError.swift */; };
F4EC3C292B6784BB006C9D11 /* TextOutputDisplayable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EC3C282B6784BB006C9D11 /* TextOutputDisplayable.swift */; };
F4EDF9F72B5F749400C3E54C /* QueueTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EDF9F62B5F749400C3E54C /* QueueTest.swift */; };
F4EDFA002B5F758400C3E54C /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = F447FC392B5E8053002A2692 /* Node.swift */; };
F4EDFA022B5FADF200C3E54C /* LinkedListTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4EDFA012B5FADF200C3E54C /* LinkedListTest.swift */; };
/* End PBXBuildFile section */

Expand All @@ -32,13 +31,15 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
2733E4F92B5F9FDB00785607 /* LinkedList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkedList.swift; sourceTree = "<group>"; };
2733E4FB2B5FA00300785607 /* Queue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
C7694E76259C3EC00053667F /* BankManagerConsoleApp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BankManagerConsoleApp; sourceTree = BUILT_PRODUCTS_DIR; };
C7694E79259C3EC00053667F /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
C7D65D1A259C8190005510E0 /* BankManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BankManager.swift; path = ../../BankManager.swift; sourceTree = "<group>"; };
F447FC382B5E50C7002A2692 /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = "<group>"; };
F447FC392B5E8053002A2692 /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = "<group>"; };
F46FA2A32B63A46A00787C3F /* BankManagerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankManagerApp.swift; sourceTree = "<group>"; };
F46FA2A72B66309000787C3F /* ConsoleManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleManager.swift; sourceTree = "<group>"; };
F46FA2A92B6630B200787C3F /* TextInputReadable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextInputReadable.swift; sourceTree = "<group>"; };
F46FA2AB2B6630CF00787C3F /* BankManagerAppMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BankManagerAppMenu.swift; sourceTree = "<group>"; };
F46FA2AD2B6630E300787C3F /* IOError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOError.swift; sourceTree = "<group>"; };
F4EC3C282B6784BB006C9D11 /* TextOutputDisplayable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextOutputDisplayable.swift; sourceTree = "<group>"; };
F4EDF9F42B5F749400C3E54C /* BankManagerConsoleAppTest.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BankManagerConsoleAppTest.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F4EDF9F62B5F749400C3E54C /* QueueTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueTest.swift; sourceTree = "<group>"; };
F4EDFA012B5FADF200C3E54C /* LinkedListTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkedListTest.swift; sourceTree = "<group>"; };
Expand All @@ -62,44 +63,65 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
C7694E6D259C3EC00053667F = {
2776CBDA2B6B8C1F00EF7155 /* Utils */ = {
isa = PBXGroup;
children = (
F447FC382B5E50C7002A2692 /* .swiftlint.yml */,
C7694E78259C3EC00053667F /* BankManagerConsoleApp */,
F4EDF9F52B5F749400C3E54C /* BankManagerConsoleAppTest */,
C7694E77259C3EC00053667F /* Products */,
F4EC3C322B6A5B82006C9D11 /* Queue.swift */,
2776CBD62B6B8BE900EF7155 /* LinkedList.swift */,
2776CBD82B6B8C1400EF7155 /* Node.swift */,
);
path = Utils;
sourceTree = "<group>";
};
C7694E77259C3EC00053667F /* Products */ = {
2776CBDB2B6B8C8C00EF7155 /* App */ = {
isa = PBXGroup;
children = (
C7694E76259C3EC00053667F /* BankManagerConsoleApp */,
F4EDF9F42B5F749400C3E54C /* BankManagerConsoleAppTest.xctest */,
F4EC3C4F2B6B6701006C9D11 /* BankManagerApp.swift */,
2776CBD22B6B852F00EF7155 /* BankManagerAppMenu.swift */,
F475FC6B2B6CC0EF00B0E859 /* BankManagerAppError.swift */,
);
name = Products;
path = App;
sourceTree = "<group>";
};
C7694E78259C3EC00053667F /* BankManagerConsoleApp */ = {
2776CBDC2B6B8CB400EF7155 /* View */ = {
isa = PBXGroup;
children = (
C7D65D1A259C8190005510E0 /* BankManager.swift */,
C7694E79259C3EC00053667F /* main.swift */,
F447FC392B5E8053002A2692 /* Node.swift */,
2733E4F92B5F9FDB00785607 /* LinkedList.swift */,
2733E4FB2B5FA00300785607 /* Queue.swift */,
F4EC3C2A2B678562006C9D11 /* App */,
F4EC3C272B678463006C9D11 /* View */,
);
path = View;
sourceTree = "<group>";
};
F4EC3C272B678463006C9D11 /* View */ = {
isa = PBXGroup;
children = (
C7694E78259C3EC00053667F /* BankManagerConsoleApp */,
C7694E77259C3EC00053667F /* Products */,
);
sourceTree = "<group>";
};
C7694E77259C3EC00053667F /* Products */ = {
isa = PBXGroup;
children = (
C7694E76259C3EC00053667F /* BankManagerConsoleApp */,
);
path = BankManagerConsoleApp;
name = Products;
sourceTree = "<group>";
};
F4EDF9F52B5F749400C3E54C /* BankManagerConsoleAppTest */ = {
isa = PBXGroup;
children = (
F4EDF9F62B5F749400C3E54C /* QueueTest.swift */,
F4EDFA012B5FADF200C3E54C /* LinkedListTest.swift */,
F4EC3C3A2B6A6C18006C9D11 /* BankerEnqueuable.swift */,
F4EC3C3E2B6A6CC3006C9D11 /* BankRunnable.swift */,
F4EC3C402B6A6CE6006C9D11 /* TaskManagable.swift */,
F4EC3C442B6A6D15006C9D11 /* ClientTaskHandlable.swift */,
F4EC3C482B6A70E7006C9D11 /* ClientEnqueuable.swift */,
2776CBD02B6B844F00EF7155 /* TextInputReadable.swift */,
F4EC3C4A2B6A71E0006C9D11 /* TextOutputDisplayable.swift */,
F4EC3C532B6B7FAE006C9D11 /* TicketProvidable.swift */,
);
path = BankManagerConsoleAppTest;
path = Protocol;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -137,7 +159,6 @@
);
name = BankManagerConsoleAppTest;
productName = BankManagerConsoleAppTest;
productReference = F4EDF9F42B5F749400C3E54C /* BankManagerConsoleAppTest.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
Expand Down Expand Up @@ -214,22 +235,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2733E4FC2B5FA00300785607 /* Queue.swift in Sources */,
F447FC3A2B5E8053002A2692 /* Node.swift in Sources */,
F46FA2AC2B6630CF00787C3F /* BankManagerAppMenu.swift in Sources */,
F46FA2AE2B6630E300787C3F /* IOError.swift in Sources */,
F46FA2AA2B6630B200787C3F /* TextInputReadable.swift in Sources */,
F46FA2A42B63A46A00787C3F /* BankManagerApp.swift in Sources */,
C7694E7A259C3EC00053667F /* main.swift in Sources */,
2733E4FA2B5F9FDB00785607 /* LinkedList.swift in Sources */,
C7D65D1B259C8190005510E0 /* BankManager.swift in Sources */,
F4EC3C292B6784BB006C9D11 /* TextOutputDisplayable.swift in Sources */,
F46FA2A82B66309000787C3F /* ConsoleManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
F4EDF9F02B5F749400C3E54C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2733E4FD2B5FA11800785607 /* LinkedList.swift in Sources */,
F4EDF9F72B5F749400C3E54C /* QueueTest.swift in Sources */,
F4EDFA002B5F758400C3E54C /* Node.swift in Sources */,
2733E4FE2B5FA11B00785607 /* Queue.swift in Sources */,
F4EDFA022B5FADF200C3E54C /* LinkedListTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F4EDF9F32B5F749400C3E54C"
BuildableName = "BankManagerConsoleAppTest.xctest"
BuildableName = "BankManagerConsoleAppTest"
BlueprintName = "BankManagerConsoleAppTest"
ReferencedContainer = "container:BankManagerConsoleApp.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// BankManagerApp.swift
// BankManagerConsoleApp
//
// Created by Effie on 2/1/24.
//

final class BankManagerApp {
func start() {
startBank()
}
}

private extension BankManagerApp {
func startBank() {
let tasks: [BankTask: ClientQueueManagable] = [
.loan: ClientManager(),
.deposit: ClientManager(),
]

let orders: [BankTask: Int] = [.loan: 2, .deposit: 3]
let bankers = makeBankers(
tasks: tasks,
orders: orders
)

BankManager(
bankers: bankers,
clientManager: tasks
).start()
}

func makeBankers(
tasks: [BankTask: any ClientQueueManagable],
orders: [BankTask: Int]
) -> [Banker] {
var result = [Banker]()
for (type, bankerCount) in orders {
(1...bankerCount).forEach { _ in
guard let clientManager = tasks[type] else { return }
let banker = Banker(clientManager: clientManager)
result.append(banker)
}
}
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// BankManagerAppError.swift
// BankManagerConsoleApp
//
// Created by Effie on 2/2/24.
//

enum BankManagerAppError: Error {
case outOfIndex
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// BankManagerAppMenu.swift
// BankManagerConsoleApp
//
// Created by 강창현 on 2/1/24.
//

enum BankManagerAppMenu {
case open
case end

private var menuNumebr: Int {
switch self {
case .open: return 1
case .end: return 2
}
}

private var description: String {
switch self {
case .open: return "은행 개점"
case .end: return "종료"
}
}

private init?(number: Int) {
switch number {
case Self.open.menuNumebr: self = .open
case Self.end.menuNumebr: self = .end
default: return nil
}
}

init(input: String) throws {
let trimmedInput = input.trimmingCharacters(in: .whitespacesAndNewlines)
guard
trimmedInput.isEmpty == false,
let number = Int(input),
let menu = Self.init(number: number)
else {
throw IOError.invalidInput
}
self = menu
}
}

extension BankManagerAppMenu: CaseIterable {
static var allMenusPrompt: String {
return allCases.enumerated().reduce(into: "") { result, indexAndMenu in
let adding = "\(indexAndMenu.element.menuNumebr) : \(indexAndMenu.element.description)"
let terminator = (indexAndMenu.offset + 1 == allCases.count) ? "" : "\n"
result += adding + terminator
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// BankManager.swift
// Created by yagom.
// Copyright © yagom academy. All rights reserved.
//

import Foundation

struct BankManager {
private let textOut: TextOutputDisplayable

private let dispenser: TicketDispenser

init(
textOut: TextOutputDisplayable,
dispenser: TicketDispenser
) {
self.textOut = textOut
self.dispenser = dispenser
}
}

extension BankManager: BankRunnable {
func runBank(with orders: [Order], numberOfClient: Int) {
let group = DispatchGroup()
let totalWorkTime = measure {
for order in orders {
let taskManager = TaskManager()
makeClients(order: order, taskManager: taskManager)
makeBankers(order: order, taskManager: taskManager)
taskManager.startTaskManaging(group: group)
}
group.wait()
}

summarizeDailyStatistics(
totalWorkTime: totalWorkTime,
numberOfClient: numberOfClient
)
}
}

private extension BankManager {
func makeBankers(order: Order, taskManager: TaskManager) {
(1...order.bankerCount).forEach { _ in
let banker = Banker(bankerEnqueuable: taskManager, resultOut: self.textOut)
taskManager.enqueueBanker(banker)
}
}

func makeClients(order: Order, taskManager: TaskManager) {
while let number = self.dispenser.provideTicket(of: order.taskType) {
let client = Client(number: number, task: order.taskType)
taskManager.enqueueClient(client)
}
}

func measure(_ progress: () -> Void) -> TimeInterval {
let start = Date()
progress()
return Date().timeIntervalSince(start)
}

func summarizeDailyStatistics(totalWorkTime: Double, numberOfClient: Int) {
let roundedWorkTimeString = String(format: "%.2f", totalWorkTime)
let output = "업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 \(numberOfClient)명이며, 총 업무시간은 \(roundedWorkTimeString)초입니다."
self.textOut.display(output: output)
}
}
Loading

0 comments on commit a1ed483

Please sign in to comment.