Last active
December 13, 2018 21:41
-
-
Save eyeezzi/addbf6a1b4597e0c89dba5a1382c621a to your computer and use it in GitHub Desktop.
Testing Extensions
This file contains hidden or 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
import Foundation | |
extension Array where Element == String { | |
func merged(into existingArray: [Element]) -> [Element] { | |
var index = Set(existingArray.map { $0.lowercased() }) | |
var container = existingArray | |
forEach { | |
if !index.contains($0.lowercased()) { | |
container.insert($0, at: container.startIndex) | |
index.insert($0) | |
} | |
} | |
return container | |
} | |
} |
This file contains hidden or 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
import XCTest | |
@testable import Shopify_POS | |
class ArrayExtensionsTests: XCTestCase { | |
func testMergeRemovesDifferentCaseDuplicates() { | |
let newWords = ["COUCH", "bed", "TaBlE"] | |
let existingWords = ["couch", "BED"] | |
let expectedMerged = ["TaBlE", "couch", "BED"] | |
let merged = newWords.merged(into: existingWords) | |
XCTAssertEqual(merged, expectedMerged) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment