<commit_before>//
//  RationalTests.swift
//  RationalTests
//
//  Created by <NAME> on 7/25/15.
//  Copyright © 2015 Buttons and Lights LLC. All rights reserved.
//

import XCTest
import SwiftCheck
@testable import Rational

extension Rational : Arbitrary {
    internal static func create(numerator n: Int) -> Int -> Rational {
        return { d in Rational(n, d)! }
    }

    public static var arbitrary: SwiftCheck.Gen<Rational> {
        return Rational.create <^> Int.arbitrary <*> Int.arbitrary.suchThat { $0 != 0 }
    }
}

class RationalTests: XCTestCase {
    func testAll() {
        property("The inverse of an inverse equals identity") <- forAll { (i : Rational) in
            return (i.numerator != 0) ==> {
                return i.inverse?.inverse! == i
            }
        }

        property("Addition is commutative") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (i + j) == (j + i)
        }

        property("Multiplication is commutative") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (i * j) == (j * i)
        }

        property("Addition is commutative 2") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals

            let caseOne = (i + j + k)
            let caseTwo = ((i + j) + k)
            let caseThree = (i + (j + k))

            return (caseOne == caseTwo) && (caseTwo == caseThree)
        }

        property("Multiplication is commutative 2") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals

            let caseOne = (i * j * k)
            let caseTwo = ((i * j) * k)
            let caseThree = (i * (j * k))

            return (caseOne == caseTwo) && (caseTwo == caseThree)
        }

        property("Division is multiplication by inverse") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (j.numerator != 0) ==> {
                return (i / j) == (i * j.inverse!)
            }
        }

        property("Multiplication by inverse is multiplicative identity") <- forAll { (i: Rational) in
            return (i.numerator != 0) ==> {
                return (i * i.inverse!) == 1
            }
        }

        property("Square maps to numerator and denominator") <- forAll { (i:Rational) in
            let squared = i * i
            return (squared.numerator == (i.numerator * i.numerator)) && (squared.denominator == (i.denominator * i.denominator))
        }

        property("Multiplication over Addition is distributive") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals
            return i * (j + k) == (i * j) + (i * k)
        }

        property("Multiplication's effect pivots on multiplicative identity") <- forAll { (input:(Int, Rational)) in
            let (i, r) = input
            let absI = abs(i)
            return (absI != 0) && (r.numerator != 0) ==> {
                if r.numerator > r.denominator {
                    return Rational(absI) * r > r
                } else if r.numerator < r.denominator {
                    return Rational(absI) * r < Rational(absI)
                } else {
                    return Rational(absI) * r == Rational(absI)
                }
            }
        }
    }
}
<commit_msg>fix typo in test<commit_after>//
//  RationalTests.swift
//  RationalTests
//
//  Created by <NAME> on 7/25/15.
//  Copyright © 2015 Buttons and Lights LLC. All rights reserved.
//

import XCTest
import SwiftCheck
@testable import Rational

extension Rational : Arbitrary {
    internal static func create(numerator n: Int) -> Int -> Rational {
        return { d in Rational(n, d)! }
    }

    public static var arbitrary: SwiftCheck.Gen<Rational> {
        return Rational.create <^> Int.arbitrary <*> Int.arbitrary.suchThat { $0 != 0 }
    }
}

class RationalTests: XCTestCase {
    func testAll() {
        property("The inverse of an inverse equals identity") <- forAll { (i : Rational) in
            return (i.numerator != 0) ==> {
                return i.inverse?.inverse! == i
            }
        }

        property("Addition is commutative") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (i + j) == (j + i)
        }

        property("Multiplication is commutative") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (i * j) == (j * i)
        }

        property("Addition is commutative 2") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals

            let caseOne = (i + j + k)
            let caseTwo = ((i + j) + k)
            let caseThree = (i + (j + k))

            return (caseOne == caseTwo) && (caseTwo == caseThree)
        }

        property("Multiplication is commutative 2") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals

            let caseOne = (i * j * k)
            let caseTwo = ((i * j) * k)
            let caseThree = (i * (j * k))

            return (caseOne == caseTwo) && (caseTwo == caseThree)
        }

        property("Division is multiplication by inverse") <- forAll { (twoRationals:(Rational, Rational)) in
            let (i, j) = twoRationals
            return (j.numerator != 0) ==> {
                return (i / j) == (i * j.inverse!)
            }
        }

        property("Multiplication by inverse is multiplicative identity") <- forAll { (i: Rational) in
            return (i.numerator != 0) ==> {
                return (i * i.inverse!) == 1
            }
        }

        property("Square maps to numerator and denominator") <- forAll { (i:Rational) in
            let squared = i * i
            return (squared.numerator == (i.numerator * i.numerator)) && (squared.denominator == (i.denominator * i.denominator))
        }

        property("Multiplication over Addition is distributive") <- forAll { (threeRationals:(Rational, Rational, Rational)) in
            let (i, j, k) = threeRationals
            return i * (j + k) == (i * j) + (i * k)
        }

        property("Multiplication's effect pivots on multiplicative identity") <- forAll { (input:(Int, Rational)) in
            let (i, r) = input
            let absI = abs(i)
            return (absI != 0) && (r.numerator != 0) ==> {
                if r.numerator > r.denominator {
                    return Rational(absI) * r > Rational(absI)
                } else if r.numerator < r.denominator {
                    return Rational(absI) * r < Rational(absI)
                } else {
                    return Rational(absI) * r == Rational(absI)
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.1302969155376189, 'fraction_numerical': 0.005477082732776016, 'mean_word_length': 1.7934782608695652, 'pattern_counts': {'":': 0, '<': 35, '<?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': '7298935', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2037, 'n_words': 597}