converted kata to swift

This commit is contained in:
khoovis
2019-09-12 20:21:08 +01:00
parent 2141835ebd
commit b1707bc029
8 changed files with 130 additions and 30 deletions

View File

@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "104F7D7323282F2900665957"
BuildableName = "Theatrical_Players_Refactoring_Kata.framework"
BlueprintName = "Theatrical-Players-Refactoring-Kata"
ReferencedContainer = "container:Theatrical-Players-Refactoring-Kata.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "104F7D7C23282F2900665957"
BuildableName = "Theatrical-Players-Refactoring-KataTests.xctest"
BlueprintName = "Theatrical-Players-Refactoring-KataTests"
ReferencedContainer = "container:Theatrical-Players-Refactoring-Kata.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "104F7D7323282F2900665957"
BuildableName = "Theatrical_Players_Refactoring_Kata.framework"
BlueprintName = "Theatrical-Players-Refactoring-Kata"
ReferencedContainer = "container:Theatrical-Players-Refactoring-Kata.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "104F7D7323282F2900665957"
BuildableName = "Theatrical_Players_Refactoring_Kata.framework"
BlueprintName = "Theatrical-Players-Refactoring-Kata"
ReferencedContainer = "container:Theatrical-Players-Refactoring-Kata.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "104F7D7323282F2900665957"
BuildableName = "Theatrical_Players_Refactoring_Kata.framework"
BlueprintName = "Theatrical-Players-Refactoring-Kata"
ReferencedContainer = "container:Theatrical-Players-Refactoring-Kata.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -10,5 +10,18 @@
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>104F7D7323282F2900665957</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>104F7D7C23282F2900665957</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@@ -1,8 +1,4 @@
struct Invoice {
let customer: String
let performances: [Performance]
init(_ customer: String, _ performances: Array<Performance>) {
self.customer = customer
self.performances = performances
}
}

View File

@@ -1,8 +1,4 @@
struct Performance {
let playID: String
let audience: Int
init(_ playID: String, _ audience: Int) {
self.playID = playID
self.audience = audience
}
}

View File

@@ -1,7 +1,3 @@
struct Play {
let name, type: String
init(_ name: String, _ type: String) {
self.name = name
self.type = type
}
}

View File

@@ -52,5 +52,3 @@ class StatementPrinter {
enum UnknownTypeError: Error {
case unknownTypeError(String)
}
// TODO: get test to pass and coverage, destructure performance object in for loop

View File

@@ -7,43 +7,44 @@ class StatementPrinterTests: XCTestCase {
let expected = """
Statement for BigCo
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Amount owed is $1,730.00
You earned 47 credits
"""
let plays = [
"hamlet": Play("Hamlet", "tragedy"),
"as-like": Play("As You Like It", "comedy"),
"othello": Play("Othello", "tragedy")
"hamlet": Play(name: "Hamlet", type: "tragedy"),
"as-like": Play(name: "As You Like It", type: "comedy"),
"othello": Play(name: "Othello", type: "tragedy")
]
let invoice = Invoice(
"BigCo", [
Performance("hamlet", 55),
Performance("as-like", 35),
Performance("othello", 40)
customer: "BigCo", performances: [
Performance(playID: "hamlet", audience: 55),
Performance(playID: "as-like", audience: 35),
Performance(playID: "othello", audience: 40)
]
)
let statementPrinter = StatementPrinter()
let result = try statementPrinter.print(invoice, plays)
XCTAssertEqual(expected, result)
XCTAssertEqual(result, expected)
}
func test_statementWithNewPlayTypes() {
let plays = [
"henry-v": Play("Henry V", "history"),
"as-like": Play("As You Like It", "pastoral")
"henry-v": Play(name: "Henry V", type: "history"),
"as-like": Play(name: "As You Like It", type: "pastoral")
]
let invoice = Invoice(
"BigCo", [
Performance("henry-v", 53),
Performance("as-like", 55)
customer: "BigCo", performances: [
Performance(playID: "henry-v", audience: 53),
Performance(playID: "as-like", audience: 55)
]
)