<commit_before>import Foundation
import XCTest

typealias MCTypeCheckFunction = (Any.Type, Any.Type, String, StaticString, UInt) -> Void

private let typeCheckFunction:MCTypeCheckFunction = { (expected, actual, message, file, line) in
    XCTAssertTrue(expected == actual, message, file: file, line:line)
}

typealias MCNSObjectEqualsFunction = (NSObject, NSObject, String, StaticString, UInt) -> Void

private let NSObjectEqualsFunction:MCNSObjectEqualsFunction = { (expected, actual, message, file, line) in
    XCTAssertEqual(expected, actual, message, file: file, line: line)
}

typealias MCOptionalStringEqualsFunction = (String?, String?, String, StaticString, UInt) -> Void

private let optionalStringEqualsFunction: MCOptionalStringEqualsFunction = { (expected, actual, message, file, line) in
    XCTAssertEqual(expected, actual, message, file: file, line: line)
}

typealias MCFailFunction = (String, StaticString, UInt) -> Void

private let failFunction: MCFailFunction = { (message, file, line) in
    XCTFail(message, file: file, line: line)
}

public func MCAssertReflectiveEqual<T>(_ expected: T, _ actual: T,
                                    file: StaticString = #file,
                                    line: UInt = #line,
                                    typeCheckFunction: MCTypeCheckFunction = typeCheckFunction,
                                    nsObjectCheckFunction: MCNSObjectEqualsFunction = NSObjectEqualsFunction,
                                    optionalStringEqualsFunction: MCOptionalStringEqualsFunction = optionalStringEqualsFunction,
                                    failFunction: MCFailFunction = failFunction) {
    var expectedVisited:[AnyObject] = []
    var actualVisited:[AnyObject] = []
    
    MCAssertReflectiveEqual(expected, actual, expectedVisited: &expectedVisited, actualVisited: &actualVisited,
                            expectedDescription: "", actualDescription: "", depth: 0,
                            file: file, line: line,
                            typeCheckFunction: typeCheckFunction,
                            nsObjectCheckFunction: nsObjectCheckFunction,
                            optionalStringEqualsFunction: optionalStringEqualsFunction,
                            failFunction: failFunction)
}

private func appendItemDescription(_ item: Any, previousDescription: String, depth: Int) -> String {
    let tabs = (0...depth).map({ _ in
        return "\t"
    }).reduce("") { (old, new) -> String in
        return old.appending(new)
    }
    
    let initialNewLine = depth == 0 ? "" : "\n"
    
    return "\(initialNewLine)\(tabs) \(item)"
}

private func MCAssertReflectiveEqual(_ expected: Any,
                                     _ actual: Any,
                                     expectedVisited: inout [AnyObject],
                                     actualVisited: inout [AnyObject],
                                     expectedDescription: String,
                                     actualDescription: String,
                                     depth: Int,
                                     file: StaticString,
                                     line: UInt,
                                     typeCheckFunction: MCTypeCheckFunction,
                                     nsObjectCheckFunction: MCNSObjectEqualsFunction,
                                     optionalStringEqualsFunction: MCOptionalStringEqualsFunction,
                                     failFunction: MCFailFunction) {
    
    let expectedDescription = appendItemDescription(expected, previousDescription: expectedDescription, depth: depth)
    let actualDescription = appendItemDescription(actual, previousDescription: actualDescription, depth: depth)
    let expectedMirror = Mirror(reflecting: expected)
    let actualMirror = Mirror(reflecting: actual)
    typeCheckFunction(expectedMirror.subjectType, actualMirror.subjectType, "Types not the same expected: \(expectedDescription) is a \(expectedMirror.subjectType) \ngot:\n\(actualDescription) which is a \(actualMirror.subjectType)", file, line)
    
    let expectedAsObject = expected as AnyObject
    let actualAsObject = actual as AnyObject
    
    if(expectedAsObject === actualAsObject) {
        return
    }
    
    var expectedChildren = expectedMirror.children
    var actualChildren = actualMirror.children
    
    guard expectedChildren.count == actualChildren.count else {
        failFunction("\(expectedDescription) has \(expectedChildren.count) but \(actualDescription) has \(actualChildren.count)", file, line)
        return
    }
    
    if(expectedChildren.count == 0) {
        if let expectedNsObj = expected as? NSObject, let actualNsObj = actual as? NSObject {
            nsObjectCheckFunction(expectedNsObj, actualNsObj, "\(expectedDescription)\nnot equal to\n\(actualDescription)", file, line)
        } else if(expectedMirror.displayStyle == actualMirror.displayStyle &&
            (expectedMirror.displayStyle == .struct || expectedMirror.displayStyle == .class)) {
            return
        } else if(expectedMirror.displayStyle == actualMirror.displayStyle && expectedMirror.displayStyle == .enum) {
            optionalStringEqualsFunction(expectedAsObject.description, actualAsObject.description, "\(expectedDescription)\nnot equal to\n\(actualDescription)", file, line)
        }
        else if(expectedMirror.description.contains("->")) {<commit_msg>use description string for enum comparison<commit_after>import Foundation
import XCTest

typealias MCTypeCheckFunction = (Any.Type, Any.Type, String, StaticString, UInt) -> Void

private let typeCheckFunction:MCTypeCheckFunction = { (expected, actual, message, file, line) in
    XCTAssertTrue(expected == actual, message, file: file, line:line)
}

typealias MCNSObjectEqualsFunction = (NSObject, NSObject, String, StaticString, UInt) -> Void

private let NSObjectEqualsFunction:MCNSObjectEqualsFunction = { (expected, actual, message, file, line) in
    XCTAssertEqual(expected, actual, message, file: file, line: line)
}

typealias MCOptionalStringEqualsFunction = (String?, String?, String, StaticString, UInt) -> Void

private let optionalStringEqualsFunction: MCOptionalStringEqualsFunction = { (expected, actual, message, file, line) in
    XCTAssertEqual(expected, actual, message, file: file, line: line)
}

typealias MCFailFunction = (String, StaticString, UInt) -> Void

private let failFunction: MCFailFunction = { (message, file, line) in
    XCTFail(message, file: file, line: line)
}

public func MCAssertReflectiveEqual<T>(_ expected: T, _ actual: T,
                                    file: StaticString = #file,
                                    line: UInt = #line,
                                    typeCheckFunction: MCTypeCheckFunction = typeCheckFunction,
                                    nsObjectCheckFunction: MCNSObjectEqualsFunction = NSObjectEqualsFunction,
                                    optionalStringEqualsFunction: MCOptionalStringEqualsFunction = optionalStringEqualsFunction,
                                    failFunction: MCFailFunction = failFunction) {
    var expectedVisited:[AnyObject] = []
    var actualVisited:[AnyObject] = []
    
    MCAssertReflectiveEqual(expected, actual, expectedVisited: &expectedVisited, actualVisited: &actualVisited,
                            expectedDescription: "", actualDescription: "", depth: 0,
                            file: file, line: line,
                            typeCheckFunction: typeCheckFunction,
                            nsObjectCheckFunction: nsObjectCheckFunction,
                            optionalStringEqualsFunction: optionalStringEqualsFunction,
                            failFunction: failFunction)
}

private func appendItemDescription(_ item: Any, previousDescription: String, depth: Int) -> String {
    let tabs = (0...depth).map({ _ in
        return "\t"
    }).reduce("") { (old, new) -> String in
        return old.appending(new)
    }
    
    let initialNewLine = depth == 0 ? "" : "\n"
    
    return "\(initialNewLine)\(tabs) \(item)"
}

private func MCAssertReflectiveEqual(_ expected: Any,
                                     _ actual: Any,
                                     expectedVisited: inout [AnyObject],
                                     actualVisited: inout [AnyObject],
                                     expectedDescription: String,
                                     actualDescription: String,
                                     depth: Int,
                                     file: StaticString,
                                     line: UInt,
                                     typeCheckFunction: MCTypeCheckFunction,
                                     nsObjectCheckFunction: MCNSObjectEqualsFunction,
                                     optionalStringEqualsFunction: MCOptionalStringEqualsFunction,
                                     failFunction: MCFailFunction) {
    
    let expectedDescription = appendItemDescription(expected, previousDescription: expectedDescription, depth: depth)
    let actualDescription = appendItemDescription(actual, previousDescription: actualDescription, depth: depth)
    let expectedMirror = Mirror(reflecting: expected)
    let actualMirror = Mirror(reflecting: actual)
    typeCheckFunction(expectedMirror.subjectType, actualMirror.subjectType, "Types not the same expected: \(expectedDescription) is a \(expectedMirror.subjectType) \ngot:\n\(actualDescription) which is a \(actualMirror.subjectType)", file, line)
    
    let expectedAsObject = expected as AnyObject
    let actualAsObject = actual as AnyObject
    
    if(expectedAsObject === actualAsObject) {
        return
    }
    
    var expectedChildren = expectedMirror.children
    var actualChildren = actualMirror.children
    
    guard expectedChildren.count == actualChildren.count else {
        failFunction("\(expectedDescription) has \(expectedChildren.count) but \(actualDescription) has \(actualChildren.count)", file, line)
        return
    }
    
    if(expectedChildren.count == 0) {
        if let expectedNsObj = expected as? NSObject, let actualNsObj = actual as? NSObject {
            nsObjectCheckFunction(expectedNsObj, actualNsObj, "\(expectedDescription)\nnot equal to\n\(actualDescription)", file, line)
        } else if(expectedMirror.displayStyle == actualMirror.displayStyle &&
            (expectedMirror.displayStyle == .struct || expectedMirror.displayStyle == .class)) {
            return
        } else if(expectedMirror.displayStyle == actualMirror.displayStyle && expectedMirror.displayStyle == .enum) {
            optionalStringEqualsFunction(String(describing: expected), String(describing: actual), "\(expectedDescription)\nnot equal to\n\(actualDescription)", file, line)
        }
        else if(expectedMirror.description.contains("->")) {
{'fraction_non_alphanumeric': 0.08445790874873772, 'fraction_numerical': 0.0007344165978151107, 'mean_word_length': 2.4301007556675063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1086226', 'n_tokens_mistral': 2642, 'n_tokens_neox': 2537, 'n_words': 653}