<commit_before>//
//  DispatchTimerTests.swift
//  ELDispatch
//
//  Created by <NAME> on 2/3/16.
//  Copyright © 2016 WalmartLabs. All rights reserved.
//

import XCTest
import ELDispatch

class DispatchTimerTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testSchedule() {
        let expectation = self.expectationWithDescription("timer fired")
        let serialQueue = DispatchQueue.Background
        let timer = DispatchTimer()
        timer.schedule(serialQueue, interval: 1) {
            expectation.fulfill()
        }

        self.waitForExpectationsWithTimeout(10, handler: nil)
    }

    func testScheduleSuspended() {
        let expectation = self.expectationWithDescription("timer fired")
        let serialQueue = DispatchQueue.Background
        let timer = DispatchTimer()
        timer.schedule(serialQueue, interval: 1, delay: 0, leeway: 1, suspended: true) {
            expectation.fulfill()
        }
        
        timer.resume()
        
        self.waitForExpectationsWithTimeout(10, handler: nil)
    }
    
}<commit_msg>Added testScheduleCancel.<commit_after>//
//  DispatchTimerTests.swift
//  ELDispatch
//
//  Created by <NAME> on 2/3/16.
//  Copyright © 2016 WalmartLabs. All rights reserved.
//

import XCTest
import ELDispatch

class DispatchTimerTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testSchedule() {
        let expectation = self.expectationWithDescription("timer fired")
        let queue = DispatchQueue.Background
        let timer = DispatchTimer()
        timer.schedule(queue, interval: 1) {
            expectation.fulfill()
        }

        self.waitForExpectationsWithTimeout(10, handler: nil)
    }

    func testScheduleSuspended() {
        let expectation = self.expectationWithDescription("timer fired")
        let queue = DispatchQueue.Background
        let timer = DispatchTimer()
        timer.schedule(queue, interval: 1, delay: 0, leeway: 1, suspended: true) {
            expectation.fulfill()
        }
        
        timer.resume()
        
        self.waitForExpectationsWithTimeout(10, handler: nil)
    }
    
    func testScheduleCancel() {
        let expectation = self.expectationWithDescription("test value checked")
        let queue = DispatchQueue.createSerial("serial")
        
        var testValue = 1
        
        let timer2 = DispatchTimer()
        timer2.schedule(queue, interval: 1) {
            testValue = 10
        }
        
        let timer1 = DispatchTimer()
        timer1.schedule(queue, interval: 2) {
            testValue = 7
        }
        
        let timer3 = DispatchTimer()
        timer3.schedule(queue, interval: 4) {
            XCTAssertEqual(testValue, 10)
            expectation.fulfill()
        }
        
        timer1.cancel()
        
        self.waitForExpectationsWithTimeout(5, handler: nil)
    }
}
{'fraction_non_alphanumeric': 0.08685714285714285, 'fraction_numerical': 0.014, 'mean_word_length': 2.156898106402164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6801931', 'n_tokens_mistral': 983, 'n_tokens_neox': 935, 'n_words': 265}