-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving protocol conformance and fixing tests
- Loading branch information
Showing
20 changed files
with
159 additions
and
129 deletions.
There are no files selected for viewing
File renamed without changes.
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,7 @@ | ||
import Foundation | ||
|
||
extension Day: Comparable { | ||
public static func < (lhs: Day, rhs: Day) -> Bool { | ||
lhs.daysSince1970 < rhs.daysSince1970 | ||
} | ||
} |
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,7 @@ | ||
import Foundation | ||
|
||
extension Day: Equatable { | ||
public static func == (lhs: Day, rhs: Day) -> Bool { | ||
lhs.daysSince1970 == rhs.daysSince1970 | ||
} | ||
} |
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,7 @@ | ||
import Foundation | ||
|
||
extension Day: Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(daysSince1970) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
import DayType | ||
import Foundation | ||
import Testing | ||
|
||
extension ProtocolConformanceSuites { | ||
|
||
@Suite("Day is Codable") | ||
struct DayCodableTests { | ||
|
||
private struct DummyType: Codable { | ||
let abc: Day | ||
} | ||
|
||
@Test("Decoding") | ||
func decoding() throws { | ||
|
||
let json = """ | ||
{ | ||
"abc": 19455 | ||
} | ||
""" | ||
|
||
let decoder = JSONDecoder() | ||
let day = try decoder.decode(DummyType.self, from: json.data(using: .utf8)!) | ||
#expect(day.abc.daysSince1970 == 19455) | ||
} | ||
|
||
@Test("Encoding") | ||
func encoding() throws { | ||
let obj = DummyType(abc: Day(daysSince1970: 19455)) | ||
let encoder = JSONEncoder() | ||
let encoded = try #require(String(data: encoder.encode(obj), encoding: .utf8)) | ||
#expect(encoded == #"{"abc":19455}"#) | ||
} | ||
} | ||
} |
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,12 @@ | ||
import DayType | ||
import Foundation | ||
import Testing | ||
|
||
extension ProtocolConformanceSuites { | ||
|
||
@Test("Day custom string convertable") | ||
func description() { | ||
let date = DateComponents(calendar: .current, year: 2001, month: 2, day: 3).date! | ||
#expect(Day(2001, 2, 3).description == date.formatted(date: .abbreviated, time: .omitted)) | ||
} | ||
} |
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,12 @@ | ||
import DayType | ||
import Foundation | ||
import Testing | ||
|
||
extension ProtocolConformanceSuites { | ||
|
||
@Test("Equatable") | ||
func equals() { | ||
#expect(Day(2020, 3, 12) == Day(2020, 3, 12)) | ||
#expect(Day(2020, 3, 12) != Day(2001, 1, 5)) | ||
} | ||
} |
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,24 @@ | ||
import DayType | ||
import Foundation | ||
import Testing | ||
|
||
extension ProtocolConformanceSuites { | ||
|
||
@Test("Hashable") | ||
func hashable() { | ||
var days: Set = [Day(2020, 01, 11), Day(2020, 01, 12)] | ||
|
||
#expect(days.contains(Day(2020, 01, 13)) == false) | ||
#expect(days.contains(Day(2020, 01, 12)) == true) | ||
|
||
// Modify and try again. | ||
days.insert(Day(2020, 01, 13)) | ||
#expect(days.count == 3) | ||
#expect(days.contains(Day(2020, 01, 13)) == true) | ||
#expect(days.contains(Day(2020, 01, 12)) == true) | ||
|
||
// Duplicate check. | ||
days.insert(Day(2020, 01, 11)) | ||
#expect(days.count == 3) | ||
} | ||
} |
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,42 @@ | ||
import DayType | ||
import Foundation | ||
import Testing | ||
|
||
extension ProtocolConformanceSuites { | ||
|
||
@Suite("Day Stridable tests") | ||
struct DayStrideableTests { | ||
|
||
@Test("In a for loop with an open range") | ||
func forEachOpenRange() { | ||
var days: [Day] = [] | ||
for day in Day(2000, 1, 1) ... Day(2000, 1, 5) { | ||
days.append(day) | ||
} | ||
#expect(days == [Day(2000, 1, 1), Day(2000, 1, 2), Day(2000, 1, 3), Day(2000, 1, 4), Day(2000, 1, 5)]) | ||
} | ||
|
||
@Test("In a for loop with a half open range") | ||
func forEachHalfOpenRange() { | ||
var days: [Day] = [] | ||
for day in Day(2000, 1, 1) ..< Day(2000, 1, 5) { | ||
days.append(day) | ||
} | ||
#expect(days == [Day(2000, 1, 1), Day(2000, 1, 2), Day(2000, 1, 3), Day(2000, 1, 4)]) | ||
} | ||
|
||
@Test("With the stride function") | ||
func forEachViaStrideFunction() { | ||
var days: [Day] = [] | ||
for day in stride(from: Day(2000, 1, 1), to: Day(2000, 1, 5), by: 2) { | ||
days.append(day) | ||
} | ||
#expect(days == [Day(2000, 1, 1), Day(2000, 1, 3)]) | ||
} | ||
|
||
@Test("Distance function") | ||
func distanceTo() { | ||
#expect(Day(2020, 3, 6).distance(to: Day(2020, 3, 12)) == 6) | ||
} | ||
} | ||
} |
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,6 @@ | ||
import Testing | ||
|
||
/// Groups up property test suites. | ||
@Suite("Protocol conformance", .tags(.ProtocolConformance)) | ||
struct ProtocolConformanceSuites {} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
File renamed without changes.
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 |
---|---|---|
|
@@ -2,5 +2,6 @@ import Testing | |
|
||
extension Tag { | ||
@Tag static var PropertyWrapper: Self | ||
@Tag static var ProtocolConformance: Self | ||
} | ||
|