Skip to content

Commit

Permalink
Change time-related arg labels
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Apr 5, 2024
1 parent 4fc0e97 commit cf1a7b0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Sources/Confidence/ConfidenceValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public class ConfidenceValue: Equatable, Encodable {
}


public init(dateComponentList: [DateComponents]) {
self.value = .list(dateComponentList.map { .date($0) })
public init(dateList: [DateComponents]) {
self.value = .list(dateList.map { .date($0) })
}

public init(dateList: [Date]) {
self.value = .list(dateList.map { .timestamp($0) })
public init(timestampList: [Date]) {
self.value = .list(timestampList.map { .timestamp($0) })
}

public init(structure: [String: ConfidenceValue]) {
Expand Down
25 changes: 22 additions & 3 deletions Tests/ConfidenceTests/ConfidenceValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,28 @@ final class ConfidenceConfidenceValueTests: XCTestCase {
XCTAssertEqual(value.asDateComponents(), dateComponents)
}

func testListShouldConvertToList() {
let value = ConfidenceValue(integerList: [3, 4])
XCTAssertEqual(value.asList(), [ConfidenceValue(integer: 3), ConfidenceValue(integer: 4)])
func testListShouldConvertToList() throws {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
formatter.timeZone = TimeZone(abbreviation: "UTC")
let date1 = try XCTUnwrap(formatter.date(from: "2022-01-01 12:00:00"))
let dateComponents1 = DateComponents(year: 2024, month: 4, day: 3)
let date2 = try XCTUnwrap(formatter.date(from: "2022-01-02 00:00:00"))
let dateComponents2 = DateComponents(year: 2024, month: 4, day: 2)

let boolListValue = ConfidenceValue(boolList: [true, false])
let integerListValue = ConfidenceValue(integerList: [3, 4])
let doubleListValue = ConfidenceValue(doubleList: [3.14, 4.0])
let stringListValue = ConfidenceValue(stringList: ["val1", "val2"])
let timestampListValue = ConfidenceValue(timestampList: [date1, date2])
let dateListValue = ConfidenceValue(dateList: [dateComponents1, dateComponents2])

XCTAssertEqual(boolListValue.asList(), [ConfidenceValue(boolean: true), ConfidenceValue(boolean: false)])
XCTAssertEqual(integerListValue.asList(), [ConfidenceValue(integer: 3), ConfidenceValue(integer: 4)])
XCTAssertEqual(doubleListValue.asList(), [ConfidenceValue(double: 3.14), ConfidenceValue(double: 4.0)])
XCTAssertEqual(stringListValue.asList(), [ConfidenceValue(string: "val1"), ConfidenceValue(string: "val2")])
XCTAssertEqual(timestampListValue.asList(), [ConfidenceValue(timestamp: date1), ConfidenceValue(timestamp: date2)])

Check warning on line 64 in Tests/ConfidenceTests/ConfidenceValueTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 123 characters (line_length)
XCTAssertEqual(dateListValue.asList(), [ConfidenceValue(date: dateComponents1), ConfidenceValue(date: dateComponents2)])

Check warning on line 65 in Tests/ConfidenceTests/ConfidenceValueTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Line Length Violation: Line should be 120 characters or less; currently it has 128 characters (line_length)
}

func testStructShouldConvertToStruct() {
Expand Down

0 comments on commit cf1a7b0

Please sign in to comment.