Skip to content

Instantly share code, notes, and snippets.

@eyeezzi
Last active December 13, 2018 21:41
Show Gist options
  • Save eyeezzi/addbf6a1b4597e0c89dba5a1382c621a to your computer and use it in GitHub Desktop.
Save eyeezzi/addbf6a1b4597e0c89dba5a1382c621a to your computer and use it in GitHub Desktop.
Testing Extensions
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
}
}
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