<commit_before>//
//  MockCMAltimeterTests.swift
//  MockCoreMotion
//
//  Created by Chucha&Masha on 3/12/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
@testable import MockCoreMotion

class MockCMAltimeterTests: XCTestCase {
    
    var testMockCMAltimeter: MockCMAltimeter?
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
        testMockCMAltimeter = MockCMAltimeter()
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        testMockCMAltimeter = nil
        super.tearDown()
    }
    
}<commit_msg>add unit tests for MockCMAltimeter<commit_after>//
//  MockCMAltimeterTests.swift
//  MockCoreMotion
//
//  Created by Chucha&Masha on 3/12/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
import CoreMotion
@testable import MockCoreMotion

class MockCMAltimeterTests: XCTestCase {
    
    var testMockCMAltimeter: MockCMAltimeter?
    class myTestError: Error {
        var _description = ""
        init(description: String) {
            _description = description
        }
        func description() -> String {
            return _description
        }
    }
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
        testMockCMAltimeter = MockCMAltimeter()
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        testMockCMAltimeter = nil
        super.tearDown()
    }
    
    func testIsRelativeAltitudeAvailable() {
        XCTAssertFalse(MockCMAltimeter.isRelativeAltitudeAvailable(), "isRelativeAltitudeAvailable() should return false by default.")
        MockCMAltimeter._isRelativeAltitudeAvailable = true
        XCTAssertTrue(MockCMAltimeter.isRelativeAltitudeAvailable())
    }
    
    func testStartRelativeAltitudeUpdates() {
        let defaultExpectation = expectation(description: "startRelativeAltitudeUpdates() should invoke handler callback with both params nil by default.")
        var testData: CMAltitudeData?
        var testError: Error?
        XCTAssertFalse(testMockCMAltimeter!.startRelativeAltitudeUpdatesCalled, "startRelativeAltitudeUpdates() should never be called.")
        testMockCMAltimeter?.startRelativeAltitudeUpdates(to: OperationQueue.main) {
            (data, error) in
            testData = data
            testError = error
            defaultExpectation.fulfill()
        }
        waitForExpectations(timeout: 3) {
            [unowned self](error) in
            guard error == nil else {
                XCTFail("Error found in expectation")
                return
            }
            XCTAssertNil(testData)
            XCTAssertNil(testError)
            XCTAssertTrue(self.testMockCMAltimeter!.startRelativeAltitudeUpdatesCalled, "startRelativeAltitudeUpdates() should be called.")
        }
        
        let dataExpectation = expectation(description: "startRelativeAltitudeUpdates() should invoke handler callback with custome data as params.")
        let testCMAltitudeData = CMAltitudeData()
        testMockCMAltimeter?.startRelativeAltitudeUpdatesHandlerData = testCMAltitudeData
        testMockCMAltimeter?.startRelativeAltitudeUpdates(to: OperationQueue.main) {
            (data, error) in
            testData = data
            testError = error
            dataExpectation.fulfill()
        }
        waitForExpectations(timeout: 3) {
            (error) in
            guard error == nil else {
                XCTFail("Error found in expectation")
                return
            }
            XCTAssertEqual(testData, testCMAltitudeData)
            XCTAssertNil(testError)
        }
        testMockCMAltimeter?.startRelativeAltitudeUpdatesHandlerData = nil
        let testErrorDescription = "Test Error"
        testMockCMAltimeter?.startRelativeAltitudeUpdatesHandlerError = myTestError(description: testErrorDescription)
        let errorExpectation = expectation(description: "startRelativeAltitudeUpdates() should invoke handler callback with custome error as params.")
        testMockCMAltimeter?.startRelativeAltitudeUpdates(to: OperationQueue.main) {
            (data, error) in
            testData = data
            testError = error
            errorExpectation.fulfill()
        }
        waitForExpectations(timeout: 3) {
            (error) in
            guard error == nil else {
                XCTFail("Error found in expectation")
                return
            }
            let castedError = testError as! myTestError
            XCTAssertNil(testData)
            XCTAssertEqual(castedError.description(), testErrorDescription)
        }
    }
    
    func testStopRelativeAltitudeUpdates() {
        XCTAssertFalse(testMockCMAltimeter!.stopRelativeAltitudeUpdatesCalled, "stopRelativeAltitudeUpdates() Should never be called")
        testMockCMAltimeter?.stopRelativeAltitudeUpdates()
        XCTAssertTrue(testMockCMAltimeter!.stopRelativeAltitudeUpdatesCalled, "stopRelativeAltitudeUpdates() Should be called")
    }

}
{'fraction_non_alphanumeric': 0.0695977549111319, 'fraction_numerical': 0.0039289055191768, 'mean_word_length': 2.55688622754491, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5992229', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1394, 'n_words': 350}