Added the test case for the range between 30 and 65.821 but now it's time to refactor.
Signed-off-by: Adam Rocska <adam.rocska@adams.solutions>
This commit is contained in:
parent
cbe43c1bc6
commit
8c21e60f20
|
@ -12,6 +12,11 @@ class ControlByteTest: XCTestCase {
|
|||
.filter({ $0.rawValue > 7 })
|
||||
.map({ $0.rawValue })
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
continueAfterFailure = false
|
||||
}
|
||||
|
||||
override class func setUp() {
|
||||
super.setUp()
|
||||
precondition(nonExtendedRawValues.count > 0, "nonExtendedRawValues can't be empty.")
|
||||
|
@ -113,4 +118,43 @@ class ControlByteTest: XCTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
func testInit_payloadSizeDefinition_exactly30() {
|
||||
let nonExtendedRawValues: [PayloadSizeTestDefinition] = ControlByteTest
|
||||
.nonExtendedRawValues
|
||||
.reduce([]) { byteSequence, typeDefinition in
|
||||
byteSequence + (285..<65_821).map({ expectedByteCount in
|
||||
var byteCountDefinition = expectedByteCount - 285
|
||||
return (
|
||||
expectedPayloadSize: UInt32(expectedByteCount),
|
||||
bytes: Data([UInt8(30) | (typeDefinition << 5)]) + Data(
|
||||
bytes: &byteCountDefinition,
|
||||
count: 2
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
let extendedRawValues: [PayloadSizeTestDefinition] = ControlByteTest
|
||||
.extendedRawValues
|
||||
.reduce([]) { byteSequence, typeDefinition in
|
||||
byteSequence + (285..<65_821).map({ expectedByteCount in
|
||||
var byteCountDefinition = expectedByteCount - 285
|
||||
return (
|
||||
expectedPayloadSize: UInt32(expectedByteCount),
|
||||
bytes: Data([UInt8(30), typeDefinition - 7]) + Data(
|
||||
bytes: &byteCountDefinition,
|
||||
count: 2
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
for (expectedPayloadSize, bytes) in (nonExtendedRawValues + extendedRawValues) {
|
||||
XCTAssertEqual(
|
||||
expectedPayloadSize,
|
||||
ControlByte(bytes: bytes)?.payloadSize,
|
||||
"Expected a payload size of \(expectedPayloadSize), but instead got \(ControlByte(bytes: bytes)?.payloadSize)"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue