<commit_before>/*
 * Appcelerator Titanium Mobile
 * Copyright (c) 2011-2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

module.exports = new function() {
    var finish;
    var valueOf;
    var reportError;
    this.init = function(testUtils) {
        finish = testUtils.finish;
        valueOf = testUtils.valueOf;
        reportError = testUtils.reportError;
    }

    this.name = "accelerometer";
    this.tests = [
        {name: "accelerometerBasic"},
        {name: "accelerometerEvent"}
    ]

    this.accelerometerBasic = function(testRun) {
        valueOf(testRun, Ti.Accelerometer).shouldBeObject();
        if (Ti.Accelerometer){
            valueOf(testRun, Ti.Accelerometer.addEventListener).shouldBeFunction();
            valueOf(testRun, Ti.Accelerometer.removeEventListener).shouldBeFunction();
            valueOf(testRun, Ti.Accelerometer.fireEvent).shouldBeFunction();
        }
        finish(testRun);
    }

    this.accelerometerEvent = function(testRun) {
        var accelerometerTestCallback = function(e) {
            valueOf(testRun, e).shouldBeObject();
            valueOf(testRun, e.timestamp).shouldBe(0);
            valueOf(testRun, e.x).shouldBe(1);
            valueOf(testRun, e.y).shouldBe(2);
            valueOf(testRun, e.z).shouldBe(3);

            setTimeout(function(){
                try{
                    Ti.Accelerometer.removeEventListener('update', accelerometerTestCallback);
                }catch (e){
                    reportError(testRun, JSON.stringify(e));
                }
                finish(testRun);
            },1000);
        };

        Ti.Accelerometer.addEventListener('update', accelerometerTestCallback);
        Ti.Accelerometer.fireEvent("update", { x: 1, y: 2, z: 3, source: this, timestamp: 0});
    }
}<commit_msg>Anvil's basic accelerometer tests<commit_after>/*
 * Appcelerator Titanium Mobile
 * Copyright (c) 2011-2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

module.exports = new function() {
    var finish;
    var valueOf;
    var reportError;
    this.init = function(testUtils) {
        finish = testUtils.finish;
        valueOf = testUtils.valueOf;
        reportError = testUtils.reportError;
    }

    this.name = "accelerometer";
    this.tests = [
        {name: "accelerometerBasic"},
        {name: "accelerometerWrongEvent"},
        {name: "accelerometerEvent"}
    ]

    this.accelerometerBasic = function(testRun) {
        valueOf(testRun, Ti.Accelerometer).shouldBeObject();
        if (Ti.Accelerometer){
            valueOf(testRun, Ti.Accelerometer.addEventListener).shouldBeFunction();
            valueOf(testRun, Ti.Accelerometer.removeEventListener).shouldBeFunction();
            valueOf(testRun, Ti.Accelerometer.fireEvent).shouldBeFunction();
        }
        finish(testRun);
    }

    this.accelerometerEvent = function(testRun) {
        var accelerometerTestCallback = function(e) {
            valueOf(testRun, e).shouldBeObject();
            valueOf(testRun, e.timestamp).shouldBe(0);
            valueOf(testRun, e.x).shouldBe(1);
            valueOf(testRun, e.y).shouldBe(2);
            valueOf(testRun, e.z).shouldBe(3);

            setTimeout(function(){
                try{
                    Ti.Accelerometer.removeEventListener('update', accelerometerTestCallback);
                }catch (e){
                    reportError(testRun, JSON.stringify(e));
                }
                finish(testRun);
            },1000);
        };

        Ti.Accelerometer.addEventListener('update', accelerometerTestCallback);
        Ti.Accelerometer.fireEvent("update", { x: 1, y: 2, z: 3, source: this, timestamp: 0});
    }


    this.accelerometerWrongEvent = function(testRun) {
        var accelerometerTestCallback = function(e) {
            reportError(testRun, "Event fired but should not!");
        };

        Ti.Accelerometer.addEventListener('update', accelerometerTestCallback);
        Ti.Accelerometer.removeEventListener('update', accelerometerTestCallback);
        Ti.Accelerometer.fireEvent("update", { x: 1, y: 2, z: 3, source: this, timestamp: 0});

        setTimeout(function(){
            valueOf(testRun, true).shouldBeTrue();
            finish(testRun);
        },1000);
    }

}
{'fraction_non_alphanumeric': 0.11523999115239991, 'fraction_numerical': 0.010617120106171201, 'mean_word_length': 2.4865073245952196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5625281', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1215, 'n_words': 250}