diff --git a/TunnelKit/Sources/Core/Data+Manipulation.swift b/TunnelKit/Sources/Core/Data+Manipulation.swift index c2779b6..faace91 100644 --- a/TunnelKit/Sources/Core/Data+Manipulation.swift +++ b/TunnelKit/Sources/Core/Data+Manipulation.swift @@ -203,7 +203,7 @@ extension Data { extension Array where Element == Data { var flatCount: Int { - return map { $0.count }.reduce(0) { $0 + $1 } + return reduce(0) { $0 + $1.count } } } diff --git a/TunnelKitTests/Core/DataManipulationTests.swift b/TunnelKitTests/Core/DataManipulationTests.swift index 14f987e..206650c 100644 --- a/TunnelKitTests/Core/DataManipulationTests.swift +++ b/TunnelKitTests/Core/DataManipulationTests.swift @@ -72,4 +72,14 @@ class DataManipulationTests: XCTestCase { XCTAssertEqual(z2.toData(), Data(hex: "5678ab")) XCTAssertEqual(z3.toData(), Data(hex: "5678abaaddcc")) } + + func testFlatCount() { + var v: [Data] = [] + v.append(Data(hex: "11223344")) + v.append(Data(hex: "1122")) + v.append(Data(hex: "1122334455")) + v.append(Data(hex: "11223344556677")) + v.append(Data(hex: "112233")) + XCTAssertEqual(v.flatCount, 21) + } }