Navigation Menu

Skip to content

Commit

Permalink
Update Dictionary lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed May 10, 2019
1 parent 331f53d commit ca28f10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 4 additions & 5 deletions SwiftUITest/XCElementType.swift
@@ -1,13 +1,12 @@
import Foundation
import XCTest


private enum ElementType : String, CaseIterable, CustomStringConvertible {
var description: String {
return String(describing: self.rawValue)
}

static var mapIntToStr: Dictionary<UInt, String> {
static var intToStr: [UInt: String] {
var result = Dictionary<UInt, String>()
var index = UInt(0)
ElementType.allCases.forEach { (element) in
Expand All @@ -17,7 +16,7 @@ private enum ElementType : String, CaseIterable, CustomStringConvertible {
return result
}

static var mapStrToInt: Dictionary<String, UInt> {
static var strToInt: [String: UInt] {
var result = Dictionary<String, UInt>()
var index = UInt(0)
ElementType.allCases.forEach { (element) in
Expand Down Expand Up @@ -119,12 +118,12 @@ public struct XCElementType {
return ele.description == type
} ?? ElementType.any

let keyNumber = ElementType.mapStrToInt[found.description] ?? 0
let keyNumber = ElementType.strToInt[found.description] ?? 0
return XCUIElement.ElementType.init(rawValue: keyNumber) ?? XCUIElement.ElementType.any
}

public static func from(_ index: UInt) -> String {
return ElementType.mapIntToStr[index] ?? ElementType.any.description
return ElementType.intToStr[index] ?? ElementType.any.description
}

public static let any: String = ElementType.any.description
Expand Down
15 changes: 10 additions & 5 deletions Tests/XCElementType_Tests.swift
Expand Up @@ -4,12 +4,17 @@ import SwiftUITest
class XCElementType_Tests: SwiftUITestCase {

func test_ElementType_to_string() {
XCTAssertTrue(XCElementType.any == "any")
XCTAssertTrue(XCElementType.other == "other")
XCTAssertEqual(XCElementType.any, "any")
XCTAssertEqual(XCElementType.other, "other")
}

func test_string_to_ElementType() {
XCTAssertTrue(XCElementType.from(XCElementType.any) == XCUIElement.ElementType.any)
XCTAssertTrue(XCElementType.from(XCElementType.other) == XCUIElement.ElementType.other)
func test_from_string_to_ElementType() {
XCTAssertEqual(XCElementType.from(XCElementType.any), XCUIElement.ElementType.any)
XCTAssertEqual(XCElementType.from(XCElementType.other), XCUIElement.ElementType.other)
}

func test_from_uint_to_string() {
XCTAssertEqual(XCElementType.from(0), "any")
XCTAssertEqual(XCElementType.from(1), "other")
}
}

0 comments on commit ca28f10

Please sign in to comment.