Sha256: 3fcc141e9e90474b81ae1dfa6be7358fdd512c1165444890b36443f800961c30
Contents?: true
Size: 1.57 KB
Versions: 29
Compression:
Stored size: 1.57 KB
Contents
import XCTest import Foundation @testable import RobotName #if os(Linux) #if swift(>=3.1) typealias Regex = NSRegularExpression #else typealias Regex = RegularExpression #endif #else typealias Regex = NSRegularExpression #endif class RobotNameTests: XCTestCase { func robotNameIsCorrectlyFormatted(_ name: String) -> Bool { let robotNameRegex = try? Regex(pattern: "\\A[A-Z]{2}\\d{3}\\z") guard let matches = robotNameRegex?.matches(in: name, options: .withoutAnchoringBounds, range: NSRange(0..<name.utf16.count)) else { return false } return matches.count > 0 } func testHasName() { let robot = Robot() XCTAssert(robotNameIsCorrectlyFormatted(robot.name)) } func testNameSticks() { let robot = Robot() let name = robot.name XCTAssertEqual(name, robot.name) } func testDifferentRobotsHaveDifferentNames() { let firstRobot = Robot() let secondRobot = Robot() XCTAssertNotEqual(firstRobot.name, secondRobot.name) } func testResetName() { var robot = Robot() let firstName = robot.name robot.resetName() let secondName = robot.name XCTAssertNotEqual(firstName, secondName) } static var allTests: [(String, (RobotNameTests) -> () throws -> Void)] { return [ ("testHasName", testHasName), ("testNameSticks", testNameSticks), ("testDifferentRobotsHaveDifferentNames", testDifferentRobotsHaveDifferentNames), ("testResetName", testResetName), ] } }
Version data entries
29 entries across 29 versions & 1 rubygems