<commit_before>//
//  SwiftStoreTests.swift
//  SwiftStore
//
//  Created by <NAME> on 4/05/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import XCTest
import SwiftStore

var q1 = DispatchQueue(label: "q1", attributes: [])

var q2 = DispatchQueue(label: "q2", attributes: [])

class SwiftStoreTests: XCTestCase {

    var store: SwiftStore!
  
    override func setUp() {
        store = SwiftStore(storeName: "db")
        super.setUp()
    }
  
    func testWrites() {
        store["apple"] = "ball"
        for i in (0 ..< 1000) {
              store["\(i)"] = "\(i)"
        }
    }

    func testReads() {
        XCTAssert(store["apple"] == "ball", "Apple -> Ball")
        for i in (0 ..< 1000) {
            XCTAssert(store["\(i)"] == "\(i)", "Written value should be read")
        }
    }

    func testMultiThreadedReads() {

        self.store["item1"] = "10"

//        dispatch_async(q1, { () -> Void in
//            self.store["item1"] = "10"
//        })

//        dispatch_async(q2, { () -> Void in
//            self.store["item1"] = "20"
//        })

        let secs = Int64(3 * Double(NSEC_PER_SEC))
        let time = DispatchTime.now() + Double(secs) / Double(NSEC_PER_SEC)
        DispatchQueue.main.asyncAfter(deadline: time, execute: { () -> Void in
            let value = self.store["item1"]
            print(value)
        })

    }

    override func tearDown() {
        store.close()
        super.tearDown()
    }
  
}<commit_msg>New tests: Collection iteration and deletion.<commit_after>//
//  SwiftStoreTests.swift
//  SwiftStore
//
//  Created by <NAME> on 4/05/2015.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import XCTest
import SwiftStore

var q1 = DispatchQueue(label: "q1", attributes: [])

var q2 = DispatchQueue(label: "q2", attributes: [])

class SwiftStoreTests: XCTestCase {

    var store: SwiftStore!
  
    override func setUp() {
        store = SwiftStore(storeName: "db")
        super.setUp()
    }
  
    func testWrites() {
        store["apple"] = "ball"
        for i in (0 ..< 1000) {
              store["\(i)"] = "\(i)"
        }
    }

    func testReads() {
        XCTAssert(store["apple"] == "ball", "Apple -> Ball")
        for i in (0 ..< 1000) {
            XCTAssert(store["\(i)"] == "\(i)", "Written value should be read")
        }
    }

    func testMultiThreadedReads() {

        self.store["item1"] = "10"

//        dispatch_async(q1, { () -> Void in
//            self.store["item1"] = "10"
//        })

//        dispatch_async(q2, { () -> Void in
//            self.store["item1"] = "20"
//        })

        let secs = Int64(3 * Double(NSEC_PER_SEC))
        let time = DispatchTime.now() + Double(secs) / Double(NSEC_PER_SEC)
        DispatchQueue.main.asyncAfter(deadline: time, execute: { () -> Void in
            let value = self.store["item1"]
            print(value)
        })

    }
    
    func testCollection() {
        
        var r1Keys = [String]()
        for i in (0 ..< 20) {
            let key = "r1-\(i)"
            r1Keys.append(key)
            
            store[key] = "r1-\(i)"
        }
        
        var r2Keys = [String]()
        for i in (0 ..< 30) {
            let key = "r2-\(i)"
            r1Keys.append(key)
            
            store[key] = "r2-\(i)"
        }
        
        var r1 = store.collect(key: "r1")
        XCTAssertEqual(r1.count, 20, "Length of collected range should be 20.")

        var r2 = store.collect(key: "r2")
        XCTAssertEqual(r2.count, 30, "Length of collected range should be 30.")
        
        // Delete collection of first keys
        store.deleteCollection(keys: r1Keys)
        
        r1 = store.collect(key: "r1")
        
        XCTAssertEqual(r1.count, 0, "After deleting a collection, the length should be 0.")
        
        // Delete second set of keys
        store.deleteCollection(keys: r2Keys)
        
        r2 = store.collect(key: "r2")
        
        XCTAssertEqual(r2.count, 0, "After deleting a collection, the length should be 0.")
        
        
    }

    override func tearDown() {
        store.close()
        super.tearDown()
    }
  
}
{'fraction_non_alphanumeric': 0.15172413793103448, 'fraction_numerical': 0.028537455410225922, 'mean_word_length': 1.727626459143969, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '7470442', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1363, 'n_words': 323}