<commit_before>//
//  PipeableTests.swift
//  Pipeline
//
//  Created by <NAME> on 2016-03-08.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import XCTest
@testable import Pipeline

class PipeableTests: XCTestCase {
  func testPipeableIsPipedWithDefaultOutputWhenConnectedToDrain() {
    let custom = IntToStringCustomType()
    let pipe = Pipe(pipeable: custom, process: {return $0})
    var output: String?
    pipe.connect(Drain { output = $0 })
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableIsPipedWithDefaultOutputWhenConnectedToPipe() {
    let custom = IntToStringCustomType()
    let pipe = Pipe(pipeable: custom, process: {return $0})
    var output: String?
    pipe.connect(Pipe<String,Void> { output = $0 })
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableUsesDefaultOutputWhenPipedToDrainUsingOperator() {
    let custom = IntToStringCustomType()
    var output: String?
    custom |- Drain {
      output = $0
    }
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableUsesDefaultInputOutputWhenPipedToPipeUsingOperator() {
    let custom = IntToStringCustomType()
    var output: String?
    custom |- Pipe<String,Void> {
      output = $0
    }
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeablesCanBeChainedWithPipeableUsingOperator() {
    let custom1 = IntToIntCustomType()
    let custom2 = IntToIntCustomType()
    var output: Int?
    custom1 |- custom2 |- Drain {
      output = $0
    }
    
    custom1.defaultPipe.insert(1)
    
    XCTAssertEqual(output, 3)
  }
}

extension PipeableTests {
  private struct IntToStringCustomType: Pipeable {
    typealias DefaultPipeInput = Int
    typealias DefaultPipeOutput = String
    
    let defaultPipe = Pipe<DefaultPipeInput, DefaultPipeOutput> { return "custom \($0)" }
    
    func pipe() -> Pipe<DefaultPipeInput, DefaultPipeOutput> {
      return defaultPipe
    }
  }
  
  private struct IntToIntCustomType: Pipeable {
    typealias DefaultPipeInput = Int
    typealias DefaultPipeOutput = Int
    
    let defaultPipe = Pipe<DefaultPipeInput, DefaultPipeOutput> { return $0 + 1 }
    
    func pipe() -> Pipe<DefaultPipeInput, DefaultPipeOutput> {
      return defaultPipe
    }
  }
  
  private struct CustomTypeWithMultipleTypeFormats {
    
  }<commit_msg>More tests for Pipeable<commit_after>//
//  PipeableTests.swift
//  Pipeline
//
//  Created by <NAME> on 2016-03-08.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import XCTest
@testable import Pipeline

class PipeableTests: XCTestCase {
  func testPipeableIsPipedWithDefaultOutputWhenConnectedToDrain() {
    let custom = IntToStringCustomType()
    let pipe = Pipe(pipeable: custom, process: {return $0})
    var output: String?
    pipe.connect(Drain { output = $0 })
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableIsPipedWithDefaultOutputWhenConnectedToPipe() {
    let custom = IntToStringCustomType()
    let pipe = Pipe(pipeable: custom, process: {return $0})
    var output: String?
    pipe.connect(Pipe<String,Void> { output = $0 })
    
    custom.defaultPipe.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableUsesDefaultOutputWhenPipedToDrainUsingOperator() {
    let custom = IntToStringCustomType()
    var output: String?
    let pipeline = custom |- Drain {
      output = $0
    }
    
    pipeline.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeableUsesDefaultInputOutputWhenPipedToPipeUsingOperator() {
    let custom = IntToStringCustomType()
    var output: String?
    let pipeline = custom |- Pipe<String,Void> {
      output = $0
    }
    
    pipeline.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
  
  func testPipeablesCanBeChainedWithPipeableUsingOperator() {
    let custom1 = IntToIntCustomType()
    let custom2 = IntToIntCustomType()
    var output: Int?
    let pipeline = custom1 |- custom2 |- Drain {
      output = $0
    }
    
    pipeline.insert(1)
    
    XCTAssertEqual(output, 3)
  }
  
  func testConsecutivePipeablesCanBeConnectedToFormPipelineUsingOperator() {
    let custom1 = IntToIntCustomType()
    let custom2 = IntToIntCustomType()
    
    var output: Int?
    let pipeline = Pipe<Int,Int>() |- custom1 |- custom2 |- Pipe<Int,Void> { output = $0 }
    pipeline.insert(1)
    
    XCTAssertEqual(output, 3)
  }
  
  func testPipesAndPipeablesCanBeMixedToFormPipelineUsingOperator() {
    let custom1 = IntToIntCustomType()
    let custom2 = IntToIntCustomType()
    
    var output: Int?
    let pipeline = Pipe<Int,Int>() |- custom1 |- Pipe() |- custom2 |- Pipe<Int,Void> { output = $0 }
    pipeline.insert(1)
    
    XCTAssertEqual(output, 3)
  }
  
  func testPipeableCanBeAtTheBeginningOfPipeline() {
    let custom = IntToStringCustomType()
    var output: String?
    let pipeline = custom |- Drain {
      output = $0
    }
    
    pipeline.insert(1)
    
    XCTAssertEqual(output, "custom 1")
  }
}

extension PipeableTests {
  private struct IntToStringCustomType: Pipeable {
    typealias DefaultPipeInput = Int
    typealias DefaultPipeOutput = String
    
    let defaultPipe = Pipe<DefaultPipeInput, DefaultPipeOutput> { return "custom \($0)" }
    
    func pipe() -> Pipe<DefaultPipeInput, DefaultPipeOutput> {
      return defaultPipe
    }
  }
  
  private struct IntToIntCustomType: Pipeable {
    typealias DefaultPipeInput = Int
    typealias DefaultPipeOutput = Int
    
    let defaultPipe = Pipe<DefaultPipeInput, DefaultPipeOutput> { return $0 + 1 }
    
    func pipe() -> Pipe<DefaultPipeInput, DefaultPipeOutput> {
      return defaultPipe
    }
  }
  
  private struct CustomTypeWithMultipleTypeFormats {
    
  }
{'fraction_non_alphanumeric': 0.09562426085487413, 'fraction_numerical': 0.015205271160669031, 'mean_word_length': 3.088397790055249, 'pattern_counts': {'":': 0, '<': 23, '<?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': '7037336', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1954, 'n_words': 410}