<commit_before>import Quick
import Nimble

import SwiftyStateMachine


private struct NumberKeeper {
    var n: Int
}


private enum Number: CustomDebugStringConvertible {
    case One, Two, Three

    var debugDescription: String {
        switch self {
            case .One: return "One"
            case .Two: return "Two"
            case .Three: return "Three"
        }
    }
}

private enum Operation {
    case Increment, Decrement

    var debugDescription: String {
        switch self {
            case .Increment: return "Increment"
            case .Decrement: return "Decrement"
        }
    }
}


extension Number: DOTLabelable {
    static var DOTLabelableItems: [Number] {
        let items: [Number] = [.One, .Two, .Three]

        // Trick: switch on all cases and get an error if you miss any.
        // Copy and paste following cases to the array above.
        for item in items {
            switch item {
                case .One, .Two, .Three: break
            }
        }

        return items
    }

    var DOTLabel: String {
        return debugDescription
    }
}

extension Operation: DOTLabelable {
    static var DOTLabelableItems: [Operation] {
        let items: [Operation] = [.Increment, .Decrement]

        // Trick: switch on all cases and get an error if you miss any.
        // Copy and paste following cases to the array above.
        for item in items {
            switch item {
                case .Increment, .Decrement: break
            }
        }

        return items
    }

    var DOTLabel: String {
        return debugDescription
    }
}


private enum SimpleState: CustomStringConvertible {
    case S1
    case S2

    var description: String {
        switch self {
            case S1: return "S1"
            case S2: return "S2"
        }
    }
}

private enum SimpleEvent { case E }

private func createSimpleSchema<T>(forward: (T -> ())? = nil, backward: (T -> ())? = nil) -> StateMachineSchema<SimpleState, SimpleEvent, T> {
    return StateMachineSchema(initialState: .S1) { (state, event) in
        switch state {
            case .S1: switch event {
                case .E: return (.S2, { forward?($0) })
            }

            case .S2: switch event {
                case .E: return (.S1, { backward?($0) })
            }
        }
    }
}

private func createSimpleMachine(forward: (() -> ())? = nil, backward: (() -> ())? = nil) -> StateMachine<StateMachineSchema<SimpleState, SimpleEvent, Void>> {
    return StateMachine(schema: createSimpleSchema(forward: { _ in forward?() }, backward: { _ in backward?() }), subject: ())
}


private class Subject {
    typealias SchemaType = StateMachineSchema<SimpleState, SimpleEvent, Subject>

    let schema: SchemaType
    lazy var machine: StateMachine<SchemaType> = { [unowned self] in
        StateMachine(schema: self.schema, subject: self)
    }()

    init(schema: SchemaType) {
        self.schema = schema
    }
}


class StateMachineSpec: QuickSpec {
    override func spec() {
        describe("State Machine") {<commit_msg> #11: fixed conversion artefacts<commit_after>import Quick
import Nimble

import SwiftyStateMachine


private struct NumberKeeper {
    var n: Int
}


private enum Number: CustomDebugStringConvertible {
    case One, Two, Three

    var debugDescription: String {
        switch self {
            case .One: return "One"
            case .Two: return "Two"
            case .Three: return "Three"
        }
    }
}

private enum Operation {
    case Increment, Decrement

    var debugDescription: String {
        switch self {
            case .Increment: return "Increment"
            case .Decrement: return "Decrement"
        }
    }
}


extension Number: DOTLabelable {
    static var DOTLabelableItems: [Number] {
        let items: [Number] = [.One, .Two, .Three]

        // Trick: switch on all cases and get an error if you miss any.
        // Copy and paste following cases to the array above.
        for item in items {
            switch item {
                case .One, .Two, .Three: break
            }
        }

        return items
    }

    var DOTLabel: String {
        return debugDescription
    }
}

extension Operation: DOTLabelable {
    static var DOTLabelableItems: [Operation] {
        let items: [Operation] = [.Increment, .Decrement]

        // Trick: switch on all cases and get an error if you miss any.
        // Copy and paste following cases to the array above.
        for item in items {
            switch item {
                case .Increment, .Decrement: break
            }
        }

        return items
    }

    var DOTLabel: String {
        return debugDescription
    }
}


private enum SimpleState: CustomStringConvertible {
    case S1
    case S2

    var description: String {
        switch self {
            case S1: return "S1"
            case S2: return "S2"
        }
    }
}

private enum SimpleEvent { case E }

private func createSimpleSchema<T>(forward forward: (T -> ())? = nil, backward: (T -> ())? = nil) -> StateMachineSchema<SimpleState, SimpleEvent, T> {
    return StateMachineSchema(initialState: .S1) { (state, event) in
        switch state {
            case .S1: switch event {
                case .E: return (.S2, { forward?($0) })
            }

            case .S2: switch event {
                case .E: return (.S1, { backward?($0) })
            }
        }
    }
}

private func createSimpleMachine(forward forward: (() -> ())? = nil, backward: (() -> ())? = nil) -> StateMachine<StateMachineSchema<SimpleState, SimpleEvent, Void>> {
    return StateMachine(schema: createSimpleSchema(forward: { _ in forward?() }, backward: { _ in backward?() }), subject: ())
}


private class Subject {
    typealias SchemaType = StateMachineSchema<SimpleState, SimpleEvent, Subject>

    let schema: SchemaType
    lazy var machine: StateMachine<SchemaType> = { [unowned self] in
        StateMachine(schema: self.schema, subject: self)
    }()

    init(schema: SchemaType) {
        self.schema = schema
    }
}


class StateMachineSpec: QuickSpec {
    override func spec() {
        describe("State Machine") {
{'fraction_non_alphanumeric': 0.09959448499594485, 'fraction_numerical': 0.004541768045417681, 'mean_word_length': 2.0570153693604363, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306950', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1694, 'n_words': 556}