<commit_before>//
//  FunctionalOperationsTests.swift
//  Operations
//
//  Created by <NAME> on 21/12/2015.
//
//

import XCTest
@testable import Operations

class NumbersOperation: Operation, ResultOperationType {

    typealias Result = Array<Int>

    var result: [Int] = []
    var error: ErrorType? = .None

    init(error: ErrorType? = .None) {
        self.error = error
        super.init()
        name = "Numbers Test"
    }

    override func execute() {
        if let error = error {
            finish(error)
        }
        else {
            result = [0, 1, 2, 3, 4, 5 , 6 , 7, 8, 9]
            finish()
        }
    }
}

class MapOperationTests: OperationTests {

    func test__map_operation() {
        let source = TestOperation()
        let destination = source.mapOperation { $0.map { "\($0) \($0)" } ?? "Nope" }

        addCompletionBlockToTestOperation(destination, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
        runOperations(source, destination)
        waitForExpectationsWithTimeout(3, handler: nil)

        XCTAssertEqual(destination.result, "Hello World Hello World")
    }

    func test__map_operation_with_error() {
        let source = TestOperation(error: TestOperation.Error.SimulatedError)
        let destination = source.mapOperation { $0.map { "\($0) \($0)" } ?? "Nope" }

        addCompletionBlockToTestOperation(destination, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
        runOperations(source, destination)
        waitForExpectationsWithTimeout(3, handler: nil)

        XCTAssertTrue(destination.cancelled)
    }
}<commit_msg>[OPR-150]: Adds tests for when the requirement wasn't set<commit_after>//
//  FunctionalOperationsTests.swift
//  Operations
//
//  Created by <NAME> on 21/12/2015.
//
//

import XCTest
@testable import Operations

class NumbersOperation: Operation, ResultOperationType {

    typealias Result = Array<Int>

    var result: [Int] = []
    var error: ErrorType? = .None

    init(error: ErrorType? = .None) {
        self.error = error
        super.init()
        name = "Numbers Test"
    }

    override func execute() {
        if let error = error {
            finish(error)
        }
        else {
            result = [0, 1, 2, 3, 4, 5 , 6 , 7, 8, 9]
            finish()
        }
    }
}

class MapOperationTests: OperationTests {

    func test__map_operation() {
        let source = TestOperation()
        let destination = source.mapOperation { $0.map { "\($0) \($0)" } ?? "Nope" }

        addCompletionBlockToTestOperation(destination, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
        runOperations(source, destination)
        waitForExpectationsWithTimeout(3, handler: nil)

        XCTAssertEqual(destination.result, "Hello World Hello World")
    }

    func test__map_operation_with_error() {
        let source = TestOperation(error: TestOperation.Error.SimulatedError)
        let destination = source.mapOperation { $0.map { "\($0) \($0)" } ?? "Nope" }

        addCompletionBlockToTestOperation(destination, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
        runOperations(source, destination)
        waitForExpectationsWithTimeout(3, handler: nil)

        XCTAssertTrue(destination.cancelled)
    }

    func test__map_operation_with_no_requirement() {
        let map: MapOperation<String, String> = MapOperation { str in return "\(str) \(str)" }

        addCompletionBlockToTestOperation(map, withExpectation: expectationWithDescription("Test: \(__FUNCTION__)"))
        runOperation(map)
        waitForExpectationsWithTimeout(3, handler: nil)

        XCTAssertTrue(map.finished)
        XCTAssertEqual(map.errors.count, 1)
    }
}
{'fraction_non_alphanumeric': 0.11589580010632643, 'fraction_numerical': 0.015151515151515152, 'mean_word_length': 2.835881753312946, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '6259583', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1067, 'n_words': 249}