<commit_before>//
//  FunctorSpec.swift
//  swiftz
//
//  Created by <NAME> on 1/19/15.
//  Copyright (c) 2015 TypeLift. All rights reserved.
//

import XCTest
import Swiftz

class FunctorSpec : XCTestCase {
	func testConst() {
		let s = "Goodbye!"
		let x : Const<String, String> = Const(s)
		XCTAssert(x.runConst == s)

		let b : Const<String, String> = x.fmap({ "I don't know why you say " + $0 })
		XCTAssert(b.runConst == s)
	}

	func testConstBifunctor() {
		let x : Const<String, String> = Const("Hello!")
		let y : Const<String, String>  = x.bimap({ "Why, " + $0 }, identity)
		XCTAssert(x.runConst != y.runConst)
	}

	func testTupleBifunctor() {
		let t : (Int, String) = (20, "Bottles of beer on the wall.")
		let y = TupleBF(t).bimap({ $0 - 1 }, identity)
		XCTAssert(y.0 != t.0)
		XCTAssert(y.1 == t.1)
	}
}<commit_msg>Convert Functor spec to properties<commit_after>//
//  FunctorSpec.swift
//  swiftz
//
//  Created by <NAME> on 1/19/15.
//  Copyright (c) 2015 TypeLift. All rights reserved.
//

import XCTest
import Swiftz
import SwiftCheck

class FunctorSpec : XCTestCase {
	func testProperties() {
		property["Const obeys the Functor identity law"] = forAll { (s : String) in
			let x = Const<String, String>(s)
			return (x.fmap(identity)).runConst == identity(x).runConst
		}

		property["Const obeys the Functor composition law"] = forAll { (f : ArrowOf<Int, Int>, g : ArrowOf<Int, Int>) in
			let x = Const<Int, Int>(5)
			return (x.fmap(f.getArrow • g.getArrow)).runConst == (x.fmap(g.getArrow).fmap(f.getArrow)).runConst
		}
	}

	func testConstBifunctor() {
		let x : Const<String, String> = Const("Hello!")
		let y : Const<String, String>  = x.bimap({ "Why, " + $0 }, identity)
		XCTAssert(x.runConst != y.runConst)
	}

	func testTupleBifunctor() {
		let t : (Int, String) = (20, "Bottles of beer on the wall.")
		let y = TupleBF(t).bimap({ $0 - 1 }, identity)
		XCTAssert(y.0 != t.0)
		XCTAssert(y.1 == t.1)
	}
}
{'fraction_non_alphanumeric': 0.16778523489932887, 'fraction_numerical': 0.01961796592669076, 'mean_word_length': 3.3550561797752807, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '749391', 'n_tokens_mistral': 821, 'n_tokens_neox': 760, 'n_words': 198}