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
| class CalculatorViewControllerTests: XCTestCase { | |
| func testEquationLabel_OnLoad_TextShouldBeEmpty() { | |
| let sut = makeLoadedViewController() | |
| XCTAssertEqual("" ,sut.EquationLabel.text) | |
| } | |
| func test_CalculateButton_TouchUpInside_ShouldCalculateEquationText() { | |
| let sut = makeLoadedViewController() | |
| sut.EquationLabel.text = "3+5" |
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
| struct Superhero: SuperheroType { | |
| let name: String | |
| let secretIdentiy: String | |
| let canFly: Bool | |
| let powerLevel: Int | |
| } | |
| protocol SuperheroType { |
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
| struct Superhero { | |
| let name: String | |
| let secretIdentiy: String | |
| let canFly: Bool | |
| let powerLevel: Int | |
| func flyToLocation(location: Location) {/* implementation */} | |
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
| func add(x: Int?, y: Int?) -> Int? { | |
| guard let x = x where x.isEven else { return .None } | |
| guard let y = y else { return .None } | |
| return x + y | |
| } |
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
| func add(x: Int?, y: Int?) -> Int? { | |
| guard let x = x, y = y where x.isEven else { return .None } | |
| return x + y | |
| } |
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
| extension IntegerType { | |
| var isEven: Bool { | |
| return self % 2 == 0 | |
| } | |
| } |
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
| func add(x: Int?, y: Int?) -> Int? { | |
| if let x = x, y = y where x.isEven { | |
| return x + y | |
| } | |
| return .None | |
| } |
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
| + (NSCharacterSet *)validCharacters { | |
| return [NSCharacterSet characterSetWithCharactersInString:@"1234567890+-*()"]; | |
| } | |
| + (BOOL)isStringValid:(NSString *)string { | |
| if (!string) return NO; | |
| NSCharacterSet *inputSet = [NSCharacterSet characterSetWithCharactersInString:string]; | |
| if (string.length > 1) { | |
| if ([[NSCharacterSet decimalDigitCharacterSet] isSupersetOfSet:inputSet]) return YES; | |
| }else { |
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
| func validInput(input:String) -> Bool { | |
| var last = "" | |
| if let x = equation.last { last = x } | |
| switch last { | |
| case "+", "-", "*", "(", "": | |
| switch input { | |
| case let x where input.toInt() != nil: | |
| return true |
NewerOlder