<commit_before>//
//  SQConnection.swift
//  SwiftQL
//
//  Created by <NAME> on 2015-01-19.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import XCTest
import SwiftQL

class SQConnectionTests: XCTestCase {

    override func setUp() {
        super.setUp()
        let db = SQDatabase()
        db.open()
        let success = db.updateMany(["DROP TABLE IF EXISTS test", "CREATE TABLE test (id INT PRIMARY KEY, name TEXT, age INT)"])
        XCTAssertTrue(success, "table should have been created")
        db.close()
    }
    
    func testInsert() {
        let conn = SQConnection()
        conn.execute({
            db in
            let success = db.update("INSERT INTO test VALUES (?, ?, ?)", withObjects: [1, "Ryan", 24])
            XCTAssertTrue(success, "insert should succeed")
        })
    }
    
    func testReadWrite() {
        let conn = SQConnection()
        let dGroup = dispatch_group_create()
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let success = db.update("INSERT INTO test VALUES (?, ?, ?)", withObjects: [1, "Ryan", 24])
            })
        })
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let cursor = db.query("SELECT * FROM test")
                XCTAssertNotNil(cursor, "cursor should not be nil")
            })
        })
        dispatch_group_wait(dGroup, DISPATCH_TIME_FOREVER)
    }

}
<commit_msg>Add additional async test<commit_after>//
//  SQConnection.swift
//  SwiftQL
//
//  Created by <NAME> on 2015-01-19.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import XCTest
import SwiftQL

class SQConnectionTests: XCTestCase {

    override func setUp() {
        super.setUp()
        let db = SQDatabase()
        db.open()
        let success = db.updateMany(["DROP TABLE IF EXISTS test", "CREATE TABLE test (id INT PRIMARY KEY, name TEXT, age INT)"])
        XCTAssertTrue(success, "table should have been created")
        db.close()
    }
    
    func testInsert() {
        let conn = SQConnection()
        conn.execute({
            db in
            let success = db.update("INSERT INTO test VALUES (?, ?, ?)", withObjects: [1, "Ryan", 24])
            XCTAssertTrue(success, "insert should succeed")
        })
    }
    
    func testReadWrite() {
        let conn = SQConnection()
        let dGroup = dispatch_group_create()
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let success = db.update("INSERT INTO test VALUES (?, ?, ?)", withObjects: [1, "Ryan", 24])
            })
        })
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let cursor = db.query("SELECT * FROM test")
                XCTAssertNotNil(cursor, "cursor should not be nil")
            })
        })
        dispatch_group_wait(dGroup, DISPATCH_TIME_FOREVER)
    }
    
    func testReadWriteAsync() {
        var idArr: [Int] = []
        var nameArr: [String] = []
        var ageArr: [Int] = []
        let conn = SQConnection()
        let dGroup = dispatch_group_create()
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            let suc = conn.transaction({
                db in
                for var i = 0; i < 1000; i++ {
                    db.update("INSERT INTO test VALUES (?, ?, ?)", withObjects: [i, "Ryan", 24])
                }
                return true
            })
        })
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let cursor = db.query("SELECT * FROM test")
                XCTAssertNotNil(cursor, "cursor should not be nil")
                if let cursor = cursor {
                    while cursor.next() {
                        //idArr.append(cursor.intForColumn("id")!)
                        //nameArr.append(cursor.stringForColumn("name")!)
                        //ageArr.append(cursor.intForColumn("age")!)
                    }
                }
            })
        })
        dispatch_group_async(dGroup, dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {
            conn.execute({
                db in
                let success = db.update("INSERT INTO test VALUES (? , ?, ?)", withObjects: [1000, "Ryan", 24])
                XCTAssertTrue(success, "insert should succeed")
            })
        })
        dispatch_group_wait(dGroup, DISPATCH_TIME_FOREVER)
        conn.execute({
            db in
            let cursor = db.query("SELECT * FROM test")
            XCTAssertNotNil(cursor, "cursor should not be nil")
            if let cursor = cursor {
                while cursor.next() {
                    idArr.append(cursor.intForColumn("id")!)
                    nameArr.append(cursor.stringForColumn("name")!)
                    ageArr.append(cursor.intForColumn("age")!)
                }
            }
        })

        XCTAssertEqual(idArr.count, 1001, "id array should contain 1001 rows")
        XCTAssertEqual(nameArr.count, 1001, "name array should contain 1001 rows")
        XCTAssertEqual(ageArr.count, 1001, "age array should contain 1001 rows")
    }

}

{'fraction_non_alphanumeric': 0.11214611872146119, 'fraction_numerical': 0.014611872146118721, 'mean_word_length': 1.798160449667859, 'pattern_counts': {'":': 0, '<': 8, '<?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': '1050736', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1527, 'n_words': 380}