<commit_before>//
//  ResultTests.swift
//  async-deferred-tests
//
//  Created by <NAME> on 2015-07-30.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest

import deferred


class ResultTests: XCTestCase
{
  func testInit()
  {
    let r1: Result<Void> = Result()
    do {
      try r1.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error is NoResult)
    }

    let r2: Result<Int> = Result()
    do {
      try r2.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error is NoResult)
    }
  }

  func testInitValue()
  {
    let val = arc4random() & 0x3fff_ffff
    let res = Result.value(val)

    do {
      let v = try res.getValue()
      XCTAssert(v == val)
    }
    catch {
      XCTFail()
    }

    XCTAssert(res.description == val.description)
  }

  func testInitError()
  {
    let err = TestError(arc4random() & 0x3fff_ffff)
    let res = Result<Int>.error(err)

    do {
      _ = try res.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error as? TestError == err)
    }

    XCTAssert(res.description.hasSuffix("\(err)"))
  }

  func testInitClosureSuccess()
  {
    let val = arc4random() & 0x3fff_ffff
    let res = Result { _ throws -> UInt32 in val }

    do {
      let v = try res.getValue()
      XCTAssert(v == val)
    }
    catch {
      XCTFail()
    }

    XCTAssert(res.description == val.description)
}

  func testInitClosureError()
  {
    let err = TestError(arc4random() & 0x3fff_ffff)
    let res = Result { _ throws -> UInt32 in throw err }

    do {
      _ = try res.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error as? TestError == err)
    }

    XCTAssert(res.description.hasSuffix("\(err)"))
  }

  func testMap()
  {
    let value = arc4random() & 0x3fff_ffff
    let goodres = Result.value(value)

    // Good operand, good transform<commit_msg>whitespace typo<commit_after>//
//  ResultTests.swift
//  async-deferred-tests
//
//  Created by <NAME> on 2015-07-30.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest

import deferred


class ResultTests: XCTestCase
{
  func testInit()
  {
    let r1: Result<Void> = Result()
    do {
      try r1.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error is NoResult)
    }

    let r2: Result<Int> = Result()
    do {
      try r2.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error is NoResult)
    }
  }

  func testInitValue()
  {
    let val = arc4random() & 0x3fff_ffff
    let res = Result.value(val)

    do {
      let v = try res.getValue()
      XCTAssert(v == val)
    }
    catch {
      XCTFail()
    }

    XCTAssert(res.description == val.description)
  }

  func testInitError()
  {
    let err = TestError(arc4random() & 0x3fff_ffff)
    let res = Result<Int>.error(err)

    do {
      _ = try res.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error as? TestError == err)
    }

    XCTAssert(res.description.hasSuffix("\(err)"))
  }

  func testInitClosureSuccess()
  {
    let val = arc4random() & 0x3fff_ffff
    let res = Result { _ throws -> UInt32 in val }

    do {
      let v = try res.getValue()
      XCTAssert(v == val)
    }
    catch {
      XCTFail()
    }

    XCTAssert(res.description == val.description)
  }

  func testInitClosureError()
  {
    let err = TestError(arc4random() & 0x3fff_ffff)
    let res = Result { _ throws -> UInt32 in throw err }

    do {
      _ = try res.getValue()
      XCTFail()
    }
    catch {
      XCTAssert(error as? TestError == err)
    }

    XCTAssert(res.description.hasSuffix("\(err)"))
  }

  func testMap()
  {
    let value = arc4random() & 0x3fff_ffff
    let goodres = Result.value(value)

    // Good operand, good transform
{'fraction_non_alphanumeric': 0.12433011789924973, 'fraction_numerical': 0.018756698821007504, 'mean_word_length': 2.105657237936772, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '1516453', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1317, 'n_words': 296}