Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Dec 22, 2019
1 parent 6f1a81c commit b9960b8
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions Tests/TLVCodingTests/TLVCodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import XCTest

final class TLVCodingTests: XCTestCase {

static var allTests = [
static let allTests = [
("testCodable", testCodable),
("testCodingKeys", testCodingKeys),
("testUUID", testUUID)
("testUUID", testUUID),
("testDate", testDate),
("testDateSecondsSince1970", testDateSecondsSince1970)
]

func testCodable() {
Expand Down Expand Up @@ -293,6 +295,28 @@ final class TLVCodingTests: XCTestCase {
}
}
}

func testDateSecondsSince1970() {

let date = Date(timeIntervalSince1970: 60 * 60 * 24 * 365)

let value = Transaction(
id: UUID(),
date: date,
description: "Test"
)

let rawValue = TransactionRaw(
id: value.id,
date: value.date.timeIntervalSince1970,
description: value.description
)

var encoder = TLVEncoder()
encoder.dateFormat = .secondsSince1970
encoder.log = { print("Encoder:", $0) }
XCTAssertEqual(try encoder.encode(value), try encoder.encode(rawValue))
}
}

// MARK: - Supporting Types
Expand All @@ -309,6 +333,20 @@ public enum Gender: UInt8, Codable {
case female
}

public struct Transaction: Equatable, Codable {

public let id: UUID
public let date: Date
public let description: String
}

public struct TransactionRaw: Equatable, Codable {

public let id: UUID
public let date: Double
public let description: String
}

public struct ProvisioningState: Codable, Equatable {

public var state: State
Expand Down

0 comments on commit b9960b8

Please sign in to comment.