Skip to content

Commit d9caf58

Browse files
authored
Merge pull request #712 from Adamant-im/trello.com/c/gJBIZ5Cf
[trello.com/c/gJBIZ5Cf]: tests for hexBytes
2 parents 6f55e8a + 3869353 commit d9caf58

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>classNames</key>
6+
<dict>
7+
<key>HexBytesTests</key>
8+
<dict>
9+
<key>test_hexBytes_performance</key>
10+
<dict>
11+
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
12+
<dict>
13+
<key>baselineAverage</key>
14+
<real>0.027400</real>
15+
<key>baselineIntegrationDisplayName</key>
16+
<string>Time</string>
17+
</dict>
18+
</dict>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>classNames</key>
6+
<dict>
7+
<key>HexBytesTests</key>
8+
<dict>
9+
<key>test_hexBytes_performance()</key>
10+
<dict>
11+
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
12+
<dict>
13+
<key>baselineAverage</key>
14+
<real>0.029200</real>
15+
<key>baselineIntegrationDisplayName</key>
16+
<string>Local Baseline</string>
17+
</dict>
18+
</dict>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>runDestinationsByUUID</key>
6+
<dict>
7+
<key>096E20D1-E7E0-41CE-A0E1-51611374B8F0</key>
8+
<dict>
9+
<key>localComputer</key>
10+
<dict>
11+
<key>busSpeedInMHz</key>
12+
<integer>0</integer>
13+
<key>cpuCount</key>
14+
<integer>1</integer>
15+
<key>cpuKind</key>
16+
<string>Apple M1</string>
17+
<key>cpuSpeedInMHz</key>
18+
<integer>0</integer>
19+
<key>logicalCPUCoresPerPackage</key>
20+
<integer>8</integer>
21+
<key>modelCode</key>
22+
<string>MacBookPro17,1</string>
23+
<key>physicalCPUCoresPerPackage</key>
24+
<integer>8</integer>
25+
<key>platformIdentifier</key>
26+
<string>com.apple.platform.macosx</string>
27+
</dict>
28+
<key>targetArchitecture</key>
29+
<string>arm64</string>
30+
<key>targetDevice</key>
31+
<dict>
32+
<key>busSpeedInMHz</key>
33+
<integer>0</integer>
34+
<key>cpuCount</key>
35+
<integer>0</integer>
36+
<key>cpuKind</key>
37+
<string></string>
38+
<key>cpuSpeedInMHz</key>
39+
<integer>0</integer>
40+
<key>logicalCPUCoresPerPackage</key>
41+
<integer>0</integer>
42+
<key>modelCode</key>
43+
<string>iPhone15,4</string>
44+
<key>physicalCPUCoresPerPackage</key>
45+
<integer>0</integer>
46+
<key>platformIdentifier</key>
47+
<string>com.apple.platform.iphonesimulator</string>
48+
</dict>
49+
</dict>
50+
<key>E6A8A214-5DA6-46B7-BBFC-56A2DDE26780</key>
51+
<dict>
52+
<key>localComputer</key>
53+
<dict>
54+
<key>busSpeedInMHz</key>
55+
<integer>0</integer>
56+
<key>cpuCount</key>
57+
<integer>1</integer>
58+
<key>cpuKind</key>
59+
<string>Apple M1</string>
60+
<key>cpuSpeedInMHz</key>
61+
<integer>0</integer>
62+
<key>logicalCPUCoresPerPackage</key>
63+
<integer>8</integer>
64+
<key>modelCode</key>
65+
<string>MacBookPro17,1</string>
66+
<key>physicalCPUCoresPerPackage</key>
67+
<integer>8</integer>
68+
<key>platformIdentifier</key>
69+
<string>com.apple.platform.macosx</string>
70+
</dict>
71+
<key>targetArchitecture</key>
72+
<string>arm64</string>
73+
<key>targetDevice</key>
74+
<dict>
75+
<key>modelCode</key>
76+
<string>iPhone15,4</string>
77+
<key>platformIdentifier</key>
78+
<string>com.apple.platform.iphonesimulator</string>
79+
</dict>
80+
</dict>
81+
</dict>
82+
</dict>
83+
</plist>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import XCTest
2+
@testable import CommonKit
3+
4+
final class HexBytesTests: XCTestCase {
5+
func test_hexBytes_smallStringWithLettersAndDigits() {
6+
let input = "48656c6c6f"
7+
let expectedOutput: [UInt8] = [0x48, 0x65, 0x6c, 0x6c, 0x6f]
8+
XCTAssertEqual(input.hexBytes(), expectedOutput)
9+
}
10+
11+
func test_hexBytes_bigStringWithAllLettersAndAllDigits() {
12+
let input = "1234567890abcdef"
13+
let expectedOutput: [UInt8] = [0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef]
14+
XCTAssertEqual(input.hexBytes(), expectedOutput)
15+
}
16+
17+
func test_hexBytes_emptyString() {
18+
let input = ""
19+
let expectedOutput: [UInt8] = []
20+
XCTAssertEqual(input.hexBytes(), expectedOutput)
21+
}
22+
23+
func test_hexBytes_withEdgeHexValues() {
24+
let input = "00ff"
25+
let expectedOutput: [UInt8] = [0x00, 0xff]
26+
XCTAssertEqual(input.hexBytes(), expectedOutput)
27+
}
28+
29+
func test_hexBytes_withUppercaseLetters() {
30+
let input = "ABCDEF"
31+
let expectedOutput: [UInt8] = [0xAB, 0xCD, 0xEF]
32+
XCTAssertEqual(input.hexBytes(), expectedOutput)
33+
}
34+
35+
func test_hexBytes_replacesInvalidHexesWithZeros() {
36+
let input = "AXBXCDEF"
37+
let expectedOutput: [UInt8] = [0x00, 0x00, 0xCD, 0xEF]
38+
XCTAssertEqual(input.hexBytes(), expectedOutput)
39+
}
40+
41+
func test_hexBytes_performance() {
42+
let input = String.init(repeating: "0123456789abcdef", count: 20000)
43+
44+
measure {
45+
_ = input.hexBytes()
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)