<commit_before>//
//  MultiplicationExpression_Tests.swift
//  DiceKit
//
//  Created by <NAME> on 7/18/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest
import Nimble
import SwiftCheck

import DiceKit

/// Tests the `MultiplicationExpression` type
class MultiplicationExpression_Tests: XCTestCase {
    
}

// MARK: - Equatable
extension MultiplicationExpression_Tests {
    
    func test_shouldBeReflexive() {
        property("reflexive") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkReflexive { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeSymmetric() {
        property("symmetric") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkSymmetric { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeTransitive() {
        property("transitive") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkTransitive { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeAbleToNotEquate() {
        property("non-equal") <- forAll {
            (a: Constant, b: Constant, m: Constant, n: Constant) in
            
            // Only check one set of parameters since not commutitive
            return (a != m || b != n) ==> {
                EquatableTestUtilities.checkNotEquate(
                    { MultiplicationExpression(a, b) },
                    { MultiplicationExpression(m, n) }
                )
            }
        }
    }
    
    func test_shouldBeAnticommutative() {
        property("anticommutative") <- forAll {
            (a: Constant, b: Constant) in
            
            return (a != b) ==> {
                let x = MultiplicationExpression(a, b)
                let y = MultiplicationExpression(b, a)
                
                return x != y
            }
        }
    }

}

// MARK: - ExpressionType
extension MultiplicationExpression_Tests {
    
    class MockExpression: ExpressionType, Equatable {
        
        typealias Result = Constant
        
        var evaluateCalled = 0
        var stubResulter: () -> Result = { 0 }
        var stubProbabilityMass = ProbabilityMass(0)
        
        func evaluate() -> Result {
            let result = stubResulter()
            ++evaluateCalled
            return result
        }
        
        var probabilityMass: ProbabilityMass {
            return stubProbabilityMass
        }
        
    }
    
    // TODO: Make a SwiftCheck
    func test_evaluate_shouldCreateResultCorrectly() {
        let multiplicandResults: [Constant] = [8, 4, 2, -7, 1, 9, 3, 3, -3, 4, 5]
        let expectedMultiplicandResults = multiplicandResults
        let leftExpression = c(expectedMultiplicandResults.count)
        let expectedMultiplierResult = leftExpression
        let mockRightExpression = MockExpression()
        mockRightExpression.stubResulter = { multiplicandResults[mockRightExpression.evaluateCalled] }
        let expression = MultiplicationExpression(leftExpression, mockRightExpression)
        
        let result = expression.evaluate()
        
        expect(result.multiplierResult) == expectedMultiplierResult
        expect(result.multiplicandResults) == expectedMultiplicandResults
    }

}

// MARK: - Operators
extension MultiplicationExpression_Tests {
    
    func test_operator_shouldWorkWithIntAndExpression() {
        property("Int * Expression and Expression * Int returns correct MultiplicationExpression") <- forAll {
            (a: Int, die: Die) in
            
            let expectedExpression1 = MultiplicationExpression(c(a), die)
            let expectedExpression2 = MultiplicationExpression(die, c(a))
            
            let expression1 = a * die
            let expression2 = die * a<commit_msg>:art: Refactor test to SwiftCheck in `MultiplicationExpression`<commit_after>//
//  MultiplicationExpression_Tests.swift
//  DiceKit
//
//  Created by <NAME> on 7/18/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import XCTest
import Nimble
import SwiftCheck

import DiceKit

/// Tests the `MultiplicationExpression` type
class MultiplicationExpression_Tests: XCTestCase {
    
}

// MARK: - Equatable
extension MultiplicationExpression_Tests {
    
    func test_shouldBeReflexive() {
        property("reflexive") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkReflexive { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeSymmetric() {
        property("symmetric") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkSymmetric { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeTransitive() {
        property("transitive") <- forAll {
            (a: Constant, b: Constant) in
            
            return EquatableTestUtilities.checkTransitive { MultiplicationExpression(a, b) }
        }
    }
    
    func test_shouldBeAbleToNotEquate() {
        property("non-equal") <- forAll {
            (a: Constant, b: Constant, m: Constant, n: Constant) in
            
            // Only check one set of parameters since not commutitive
            return (a != m || b != n) ==> {
                EquatableTestUtilities.checkNotEquate(
                    { MultiplicationExpression(a, b) },
                    { MultiplicationExpression(m, n) }
                )
            }
        }
    }
    
    func test_shouldBeAnticommutative() {
        property("anticommutative") <- forAll {
            (a: Constant, b: Constant) in
            
            return (a != b) ==> {
                let x = MultiplicationExpression(a, b)
                let y = MultiplicationExpression(b, a)
                
                return x != y
            }
        }
    }

}

// MARK: - ExpressionType
extension MultiplicationExpression_Tests {
    
    class MockExpression: ExpressionType, Equatable {
        
        typealias Result = Constant
        
        var evaluateCalled = 0
        var stubResulter: () -> Result = { 0 }
        var stubProbabilityMass = ProbabilityMass(0)
        
        func evaluate() -> Result {
            let result = stubResulter()
            ++evaluateCalled
            return result
        }
        
        var probabilityMass: ProbabilityMass {
            return stubProbabilityMass
        }
        
    }
    
    func test_evaluate_shouldCreateResultCorrectly() {
        property("evaluate") <- forAll {
            (a: ArrayOf<Constant>) in
        
            let multiplicandResults = a.getArray
            let expectedMultiplicandResults = multiplicandResults
            let leftExpression = c(expectedMultiplicandResults.count)
            let expectedMultiplierResult = leftExpression
            let mockRightExpression = MockExpression()
            mockRightExpression.stubResulter = { multiplicandResults[mockRightExpression.evaluateCalled] }
            let expression = MultiplicationExpression(leftExpression, mockRightExpression)
            
            let result = expression.evaluate()
            
            let testMultiplierResult = result.multiplierResult == expectedMultiplierResult
            let testMultiplicandResults = result.multiplicandResults == expectedMultiplicandResults
            
            return testMultiplierResult && testMultiplicandResults
        }
    }

}

// MARK: - Operators
extension MultiplicationExpression_Tests {
    
    func test_operator_shouldWorkWithIntAndExpression() {
        property("Int * Expression and Expression * Int returns correct MultiplicationExpression") <- forAll {
            (a: Int, die: Die) in
            
            let expectedExpression1 = MultiplicationExpression(c(a), die)
            let expectedExpression2 = MultiplicationExpression(die, c(a))
            
            let expression1 = a * die
            let expression2 = die * a
{'fraction_non_alphanumeric': 0.08157732593961799, 'fraction_numerical': 0.00529882932840419, 'mean_word_length': 1.9480566654558664, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 16, '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': '7652879', 'n_tokens_mistral': 2124, 'n_tokens_neox': 2057, 'n_words': 490}