Can't get tests any better than they are for now.

Signed-off-by: Adam Rocska <adam.rocska@adams.solutions>
This commit is contained in:
Adam Rocska 2020-05-01 13:05:09 +02:00
parent 3901f2dc1a
commit cc4305f2d2
1 changed files with 10 additions and 6 deletions

View File

@ -107,21 +107,25 @@ fileprivate typealias PayloadSizeTestDefinition = (
bytes: Data
)
/// TODO: Ugly piece of code, but it works. I could revisit in the future to
/// refactor it.
fileprivate func payloadSizeTestDefiner(
rawValues: [DataType.RawValue],
createLeadingBytes: @escaping (UInt8, UInt8) -> Data
) -> (PayloadSpec) -> [PayloadSizeTestDefinition] {
return { payloadSpec in
let (validValueRange, addedValue, payloadSizeDefinition) = payloadSpec
return rawValues
rawValues
.reduce([]) { byteSequence, typeDefinition in
byteSequence + validValueRange.map({ expectedByteCount in
var byteCountDefinition = expectedByteCount - addedValue
byteSequence + payloadSpec.validValueRange.map({ expectedByteCount in
var byteCountDefinition = expectedByteCount - payloadSpec.addedValue
return (
expectedPayloadSize: UInt32(expectedByteCount),
bytes: createLeadingBytes(payloadSizeDefinition, typeDefinition) + Data(
bytes: createLeadingBytes(
payloadSpec.payloadSizeDefinition,
typeDefinition
) + Data(
bytes: &byteCountDefinition,
count: Int(payloadSizeDefinition & 0b0000_0011)
count: Int(payloadSpec.payloadSizeDefinition & 0b0000_0011)
)
)
})