<commit_before>import Foundation

struct _BeCloseToMatcher: MatcherWithFullMessage {
    let expectedValue: Double
    let delta: Double

    func isCloseTo(actualValue: Double, negate: Bool) -> (Bool, String) {
        var args = VaListBuilder()
        args.append(actualValue)
        args.append(negate ? "to not" : "to")
        args.append(expectedValue)
        args.append(delta)
        let message = NSString(format: "expected <%.4f> %@ be close to <%.4f> (within %.4f)", arguments: args.va_list())
        return ((abs(actualValue - expectedValue) < delta) == !negate, message)
    }

    func matches(actualExpression: Expression<Double>) -> (pass: Bool, message: String)  {
        let actualValue = actualExpression.evaluate()
        return isCloseTo(actualValue, negate: false)
    }

    func doesNotMatch(actualExpression: Expression<Double>) -> (pass: Bool, message: String)  {
        let actualValue = actualExpression.evaluate()
        return isCloseTo(actualValue, negate: true)
    }
}

func beCloseTo(expectedValue: Double, within delta: Double = 0.0001) -> _BeCloseToMatcher {
    return _BeCloseToMatcher(expectedValue: expectedValue, delta: delta)
}

func ==(lhs: Expectation<Double>, rhs: Double) -> Bool {
    lhs.to(beCloseTo(rhs))
    return true
}<commit_msg>Minor refactoring.<commit_after>import Foundation

struct _BeCloseToMatcher: MatcherWithFullMessage {
    let expectedValue: Double
    let delta: Double

    func isCloseTo(actualValue: Double, negate: Bool) -> (Bool, String) {
        var args = VaListBuilder()
        args.append(actualValue)
        args.append(negate ? "to not" : "to")
        args.append(expectedValue)
        args.append(delta)
        let message = NSString(format: "expected <%.4f> %@ be close to <%.4f> (within %.4f)", arguments: args.va_list())
        return ((abs(actualValue - expectedValue) < delta) == !negate, message)
    }

    func matches(actualExpression: Expression<Double>) -> (pass: Bool, message: String)  {
        return isCloseTo(actualExpression.evaluate(), negate: false)
    }

    func doesNotMatch(actualExpression: Expression<Double>) -> (pass: Bool, message: String)  {
        return isCloseTo(actualExpression.evaluate(), negate: true)
    }
}

func beCloseTo(expectedValue: Double, within delta: Double = 0.0001) -> _BeCloseToMatcher {
    return _BeCloseToMatcher(expectedValue: expectedValue, delta: delta)
}

func ==(lhs: Expectation<Double>, rhs: Double) -> Bool {
    lhs.to(beCloseTo(rhs))
    return true
}
{'fraction_non_alphanumeric': 0.12365805168986084, 'fraction_numerical': 0.006361829025844931, 'mean_word_length': 3.6335174953959486, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '2355973', 'n_tokens_mistral': 771, 'n_tokens_neox': 741, 'n_words': 189}