<commit_before>import XCTest
@testable import CUDARuntime
import NVRTC

class CUDARuntimeTests: XCTestCase {

    func testDevice() {
        let computability = Device.current.computeCapability
        XCTAssertGreaterThanOrEqual(computability.major, 1)
        XCTAssertGreaterThanOrEqual(computability.minor, 0)
    }

    func testPointer() {
        measure {
            let localArray: ContiguousArray = [1, 2, 3, 4, 5, 6, 7, 8]
            let pointer = UnsafeMutableDevicePointer<Int>.allocate(capacity: 8)
            pointer.assign(fromHost: localArray)
            XCTAssertEqual(pointer.load(), 1)
            for i in localArray.indices {
                XCTAssertEqual(localArray[i], pointer[i])
            }
            /// Add one to each device element
            for i in localArray.indices {
                pointer[i] += 1
                XCTAssertEqual(localArray[i] + 1, pointer[i])
            }
            pointer.deallocate()
        }
    }

    func testArray() {
        let hostArray: [Int] = [1, 2, 3, 4, 5]
        /// Array literal initialization!
        let devArray: DeviceArray<Int> = [1, 2, 3, 4, 5]
        XCTAssertEqual(hostArray, Array(devArray))
        let hostArrayFromDev: [Int] = devArray.copyToHost()
        XCTAssertEqual(hostArray, hostArrayFromDev)

        /// Test copy-on-write
        var devArray2 = devArray
        var devArray3 = devArray
        devArray2[0].value = 3
        XCTAssertNotEqual(Array(devArray), Array(devArray2))
        devArray3[0].value = 4
        XCTAssertNotEqual(Array(devArray2), Array(devArray3))
        XCTAssertEqual(Array(devArray), Array(devArray))
        XCTAssertEqual(Array(devArray), [1, 2, 3, 4, 5])
        XCTAssertEqual(Array(devArray2), [3, 2, 3, 4, 5])
        XCTAssertEqual(Array(devArray3), [4, 2, 3, 4, 5])
    }<commit_msg>A tad more test<commit_after>import XCTest
@testable import CUDARuntime
import NVRTC

class CUDARuntimeTests: XCTestCase {

    func testDevice() {
        let computability = Device.current.computeCapability
        XCTAssertGreaterThanOrEqual(computability.major, 1)
        XCTAssertGreaterThanOrEqual(computability.minor, 0)
    }

    func testPointer() {
        measure {
            let localArray: ContiguousArray = [1, 2, 3, 4, 5, 6, 7, 8]
            let pointer = UnsafeMutableDevicePointer<Int>.allocate(capacity: 8)
            pointer.assign(fromHost: localArray)
            XCTAssertEqual(pointer.load(), 1)
            for i in localArray.indices {
                XCTAssertEqual(localArray[i], pointer[i])
            }
            /// Add one to each device element
            for i in localArray.indices {
                pointer[i] += 1
                XCTAssertEqual(localArray[i] + 1, pointer[i])
            }
            pointer.deallocate()
        }
    }

    func testArray() {
        let hostArray: [Int] = [1, 2, 3, 4, 5]
        /// Array literal initialization!
        let devArray: DeviceArray<Int> = [1, 2, 3, 4, 5]
        XCTAssertEqual(hostArray, Array(devArray))
        let hostArrayFromDev: [Int] = devArray.copyToHost()
        XCTAssertEqual(hostArray, hostArrayFromDev)

        /// Test copy-on-write
        var devArray2 = devArray
        var devArray3 = devArray
        let devArray4 = devArray3
        devArray2[0].value = 3
        XCTAssertNotEqual(Array(devArray), Array(devArray2))
        devArray3[0].value = 4
        var val3_0 = devArray3[0]
        var origVal3_0 = val3_0
        XCTAssertEqual(val3_0.value, 4)
        val3_0.value = 10
        XCTAssertEqual(val3_0.value, 10)
        XCTAssertEqual(origVal3_0.value, 4)
        XCTAssertNotEqual(Array(devArray2), Array(devArray3))
        XCTAssertEqual(devArray.copyToHost(), Array(devArray))
        XCTAssertEqual(devArray.copyToHost(), [1, 2, 3, 4, 5])
        XCTAssertEqual(devArray2.copyToHost(), [3, 2, 3, 4, 5])
        XCTAssertEqual(devArray3.copyToHost(), [4, 2, 3, 4, 5])
        XCTAssertEqual(devArray4.copyToHost(), [1, 2, 3, 4, 5])
    }
{'fraction_non_alphanumeric': 0.10750810675979047, 'fraction_numerical': 0.033424794213020706, 'mean_word_length': 2.3195364238410594, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3391240', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1248, 'n_words': 282}