-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from brightdigit/feature/pattern-matching
Feature/pattern matching
- Loading branch information
Showing
11 changed files
with
171 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol Base32CrockfordComparer { | ||
func data(_ data: Data, hasEncodedPrefix prefix: String) -> Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@testable import Base32Crockford | ||
import XCTest | ||
|
||
final class Base32EqualityTests: XCTestCase { | ||
func testExample() { | ||
let values = ["0": "O", "1": "I", "I": "L"] | ||
let encoding = Base32CrockfordEncoding() | ||
var checks = 0 | ||
for _ in 0 ... 2000 { | ||
let id = UUID() | ||
let data = Data(Array(uuid: id)) | ||
let fullId = encoding.encode(data: data) | ||
let shortId = String(fullId[fullId.startIndex ... fullId.index(fullId.startIndex, offsetBy: 4)]) | ||
var shortValues = values.reduce([shortId]) { (shortValues, arg1) -> [String] in | ||
|
||
let (key, value) = arg1 | ||
let current = shortValues.last ?? shortId | ||
|
||
return shortValues + [current.replacingOccurrences(of: key, with: value)] | ||
} | ||
shortValues.append((shortValues.last ?? shortId).lowercased()) | ||
shortValues = [String](Set(shortValues)) | ||
for aShortId in shortValues { | ||
XCTAssert(Base32CrockfordEncoding.comparer.data(data, hasEncodedPrefix: aShortId)) | ||
checks += 1 | ||
} | ||
if checks > 500 { | ||
return | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
**PROTOCOL** | ||
|
||
# `Base32CrockfordComparer` | ||
|
||
```swift | ||
public protocol Base32CrockfordComparer | ||
``` | ||
|
||
## Methods | ||
### `data(_:hasEncodedPrefix:)` | ||
|
||
```swift | ||
func data(_ data: Data, hasEncodedPrefix prefix: String) -> Bool | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters