Skip to content

Commit 8c1e827

Browse files
committed
added tests
1 parent 029c749 commit 8c1e827

File tree

4 files changed

+139
-14
lines changed

4 files changed

+139
-14
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1530"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "some-codable-swift"
19+
BuildableName = "some-codable-swift"
20+
BlueprintName = "some-codable-swift"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
<Testables>
33+
<TestableReference
34+
skipped = "NO">
35+
<BuildableReference
36+
BuildableIdentifier = "primary"
37+
BlueprintIdentifier = "some-codable-swiftTests"
38+
BuildableName = "some-codable-swiftTests"
39+
BlueprintName = "some-codable-swiftTests"
40+
ReferencedContainer = "container:">
41+
</BuildableReference>
42+
</TestableReference>
43+
</Testables>
44+
</TestAction>
45+
<LaunchAction
46+
buildConfiguration = "Debug"
47+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
48+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
launchStyle = "0"
50+
useCustomWorkingDirectory = "NO"
51+
ignoresPersistentStateOnLaunch = "NO"
52+
debugDocumentVersioning = "YES"
53+
debugServiceExtension = "internal"
54+
allowLocationSimulation = "YES">
55+
</LaunchAction>
56+
<ProfileAction
57+
buildConfiguration = "Release"
58+
shouldUseLaunchSchemeArgsEnv = "YES"
59+
savedToolIdentifier = ""
60+
useCustomWorkingDirectory = "NO"
61+
debugDocumentVersioning = "YES">
62+
<MacroExpansion>
63+
<BuildableReference
64+
BuildableIdentifier = "primary"
65+
BlueprintIdentifier = "some-codable-swift"
66+
BuildableName = "some-codable-swift"
67+
BlueprintName = "some-codable-swift"
68+
ReferencedContainer = "container:">
69+
</BuildableReference>
70+
</MacroExpansion>
71+
</ProfileAction>
72+
<AnalyzeAction
73+
buildConfiguration = "Debug">
74+
</AnalyzeAction>
75+
<ArchiveAction
76+
buildConfiguration = "Release"
77+
revealArchiveInOrganizer = "YES">
78+
</ArchiveAction>
79+
</Scheme>

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Some codable
1+
# SomeCodable
22
## Subsidiary package
33

44
### SomeEncodable
@@ -17,7 +17,7 @@ A type that can encode itself to an external representation from different types
1717
print(str)
1818
}
1919
```
20-
*[{"name":"User"},640,20.649999999999999,"DPMSolverMultistep"]*
20+
*[{"name":"User"},640,20.65,"DPMSolverMultistep"]*
2121

2222
```swift
2323
struct User: Encodable{
@@ -34,4 +34,4 @@ A type that can encode itself to an external representation from different types
3434

3535
```
3636

37-
*{"width":640,"data":{"name":"User"},"num_inference_steps":20.649999999999999}*
37+
*{"width":640,"data":{"name":"User"},"num_inference_steps":20.65}*
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import XCTest
2+
@testable import some_codable_swift
3+
4+
final class SomeEncodableTests: XCTestCase {
5+
6+
struct User: Encodable{
7+
let name: String
8+
}
9+
10+
func testEncodeHeterogeneousArray() throws {
11+
12+
let arr : [SomeEncodable] = [
13+
.init(User(name: "User")), 640, 20.65, "DPMSolverMultistep"
14+
]
15+
16+
let expected = "[{\"name\":\"User\"},640,20.65,\"DPMSolverMultistep\"]"
17+
18+
19+
let encode = try JSONEncoder().encode(arr)
20+
21+
let str = String(decoding: encode, as: UTF8.self)
22+
23+
XCTAssertEqual(expected, str)
24+
25+
}
26+
27+
func testEncodeHeterogeneousDictionary() throws {
28+
29+
let dic : [String: SomeEncodable] = [
30+
"data" : .init(User(name: "User")),
31+
"width" : 640,
32+
"num_inference_steps" : 20.65
33+
]
34+
35+
let expected = "{\"width\":640,\"num_inference_steps\":20.65,\"data\":{\"name\":\"User\"}}".data(using: .utf8)!
36+
let expectedJSON = try JSONSerialization.jsonObject(with: expected, options: []) as! NSDictionary
37+
38+
let encode = try JSONEncoder().encode(dic)
39+
let encodedJSON = try JSONSerialization.jsonObject(with: encode, options: []) as! NSDictionary
40+
41+
42+
43+
XCTAssertEqual(encodedJSON, expectedJSON)
44+
}
45+
46+
func testCompareNilExpressible(){
47+
let someNil : [SomeEncodable] = [nil, nil, nil]
48+
49+
XCTAssertEqual(someNil, [nil, nil, nil])
50+
}
51+
52+
func testCompareBoolExpressible(){
53+
let someBool : SomeEncodable = true
54+
55+
XCTAssertEqual(someBool, true)
56+
}
57+
}

Tests/some-codable-swiftTests/some_codable_swiftTests.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)