<commit_before>//
//  LockTests.swift
//  MacDemos
//
//  Created by <NAME> on 6/12/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import XCTest
@testable import BezierKit

class LockTests: XCTestCase {
    func testPathPropertyAtomicity() {
        // ensure that lazy properties of Path are only initialized once
        let squareCGPath = CGPath(rect: CGRect(x: 0, y: 0, width: 1, height: 1), transform: nil)
        let path = Path(cgPath: squareCGPath)

        let threadCount = 10000
        let expectation = XCTestExpectation()
        expectation.expectedFulfillmentCount = threadCount

        var cgPaths: [Int: CGPath] = [:]
        var boundingBoxes: [Int: BoundingBox] = [:]

        for i in 0..<threadCount {
            let index = i
            DispatchQueue.global(qos: .default).async {
                let pathValue = path.cgPath
                let boundingBoxValue = path.boundingBox
                DispatchQueue.main.async {
                    cgPaths[index] = pathValue
                    boundingBoxes[index] = boundingBoxValue
                    expectation.fulfill()
                }
            }
        }
        wait(for: [expectation], timeout: 10.0)

        XCTAssertEqual(cgPaths.values.count, threadCount)
        XCTAssertEqual(cgPaths[0], Path(cgPath: squareCGPath).cgPath)
        XCTAssertTrue(cgPaths.values.allSatisfy { $0 === cgPaths[0] }, "cgPaths should all refer to the same instance (was it initialized more than once?)")

        let expectedBoundingBox = Path(cgPath: squareCGPath).boundingBox
        XCTAssertEqual(boundingBoxes.values.count, threadCount)
        XCTAssertTrue(boundingBoxes.values.allSatisfy { $0 == expectedBoundingBox })
    }
}
<commit_msg>lock tests should run on Linux.<commit_after>//
//  LockTests.swift
//  MacDemos
//
//  Created by <NAME> on 6/12/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import XCTest
@testable import BezierKit

class LockTests: XCTestCase {
    func testPathPropertyAtomicity() {
        // ensure that lazy properties of Path are only initialized once
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        let path = Path(rect: rect)

        let threadCount = 10000
        let expectation = XCTestExpectation()
        expectation.expectedFulfillmentCount = threadCount

    #if canImport(CoreGraphics)
        var cgPaths: [Int: CGPath] = [:]
    #endif
        var boundingBoxes: [Int: BoundingBox] = [:]

        for i in 0..<threadCount {
            let index = i
            DispatchQueue.global(qos: .default).async {
                #if canImport(CoreGraphics)
                let pathValue = path.cgPath
                #endif
                let boundingBoxValue = path.boundingBox
                DispatchQueue.main.async {
                #if canImport(CoreGraphics)
                    cgPaths[index] = pathValue
                #endif
                    boundingBoxes[index] = boundingBoxValue
                    expectation.fulfill()
                }
            }
        }
        wait(for: [expectation], timeout: 10.0)

        #if canImport(CoreGraphics)
        XCTAssertEqual(cgPaths.values.count, threadCount)
        XCTAssertEqual(cgPaths[0], Path(rect: rect).cgPath)
        XCTAssertTrue(cgPaths.values.allSatisfy { $0 === cgPaths[0] }, "cgPaths should all refer to the same instance (was it initialized more than once?)")
        #endif

        let expectedBoundingBox = Path(rect: rect).boundingBox
        XCTAssertEqual(boundingBoxes.values.count, threadCount)
        XCTAssertTrue(boundingBoxes.values.allSatisfy { $0 == expectedBoundingBox })
    }
}

{'fraction_non_alphanumeric': 0.09620670698185817, 'fraction_numerical': 0.014293567894447499, 'mean_word_length': 2.175392670157068, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4810129', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1031, 'n_words': 262}