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

Version Path
trackler-2.2.1.180 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.179 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.178 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.177 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.176 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.175 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.174 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.173 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.172 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.171 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.170 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.169 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.167 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.166 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.165 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.164 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.163 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.162 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.161 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift
trackler-2.2.1.160 tracks/swift/exercises/robot-name/Tests/RobotNameTests/RobotNameTests.swift