<commit_before>module("timer.js", {
    beforeEach: function() {
        this.output = document.getElementById("output");
        this.output.value = "";
    }
});

test("Setup", function(assert) {
    assert.expect(3);
    var t = new Timer(10, this.output);
    assert.equal(t.offset, 10);
    assert.equal(t.output, this.output);
    assert.ok(!t.running);
});

test("start", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    assert.ok(t.running);
    assert.notEqual(t.startTime, 0);
    t.stop();
});

test("start event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    this.output.addEventListener("start", function() {
        assert.push("Start event fired");
        t.stop();
        done();
    });
    t.start();
});

test("pause", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    setTimeout(function() {
        t.pause();
        assert.ok(!t.running);
        assert.ok(995 < t.offset && t.offset < 1005);
        done();
    }, 1000);
});

test("pause event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    this.output.addEventListener("pause", function(e) {
        assert.equal(t.offset, e.detail);
        done();
    });
    setTimeout(function() {
        t.pause();
    }, 1000);
});

test("updateOutput", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    setTimeout(function() {
        t.pause();
        t.updateOutput();
        assert.equal(t.output.value, "1.0");
        t.updateOutput(1100);
        assert.equal(t.output.value, "1.1");
        done();
    }, 1000);
});

test("stop", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    t.stop();
    assert.ok(!t.running);
    assert.equal(t.startTime, 0);
    assert.equal(t.offset, 0);
    assert.equal(this.output.value, "0.0");
});

test("stop event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    this.output.addEventListener("stop", function(e) {
        assert.notEqual(e.detail, 0);
        done();
    });
    setTimeout(function() {
        t.stop();
    }, 100);
});

test("getTime", function(assert) {
    var t = new Timer(10, this.output);
    assert.equal(t.getTime(), 10);
    t.running = true;
    assert.equal(t.getTime(), Date.now());
    t.running = false;
});

test("reset", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    t.reset();
    assert.ok(!t.running);
    assert.equal(t.startTime, 0);
    assert.equal(t.offset, 0);
    assert.equal(this.output.value, "0.0");
});

test("reset event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    this.output.addEventListener("reset", function() {
        assert.push("Reset event fired");
        done();
    });
    t.reset();
});

<commit_msg>Make timer tests less error prone, as in, lift the delta for over/underrun to 50ms<commit_after>module("timer.js", {
    beforeEach: function() {
        this.output = document.getElementById("output");
        this.output.value = "";
        this.delta = 50;
    }
});

test("Setup", function(assert) {
    assert.expect(3);
    var t = new Timer(10, this.output);
    assert.equal(t.offset, 10);
    assert.equal(t.output, this.output);
    assert.ok(!t.running);
});

test("start", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    assert.ok(t.running);
    assert.notEqual(t.startTime, 0);
    t.stop();
});

test("start event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    this.output.addEventListener("start", function() {
        assert.push("Start event fired");
        t.stop();
        done();
    });
    t.start();
});

test("pause", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    var self = this;
    t.start();
    setTimeout(function() {
        t.pause();
        assert.ok(!t.running);
        assert.ok(Math.abs(t.offset - 1000) < self.delta);
        done();
    }, 1000);
});

test("pause event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    this.output.addEventListener("pause", function(e) {
        assert.equal(t.offset, e.detail);
        done();
    });
    setTimeout(function() {
        t.pause();
    }, 1000);
});

test("updateOutput", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    setTimeout(function() {
        t.pause();
        t.updateOutput();
        assert.equal(t.output.value, "1.0");
        t.updateOutput(1100);
        assert.equal(t.output.value, "1.1");
        done();
    }, 1000);
});

test("stop", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    t.stop();
    assert.ok(!t.running);
    assert.equal(t.startTime, 0);
    assert.equal(t.offset, 0);
    assert.equal(this.output.value, "0.0");
});

test("stop event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    t.start();
    this.output.addEventListener("stop", function(e) {
        assert.notEqual(e.detail, 0);
        done();
    });
    setTimeout(function() {
        t.stop();
    }, 100);
});

test("getTime", function(assert) {
    var t = new Timer(10, this.output);
    assert.equal(t.getTime(), 10);
    t.running = true;
    assert.equal(t.getTime(), Date.now());
    t.running = false;
});

test("reset", function(assert) {
    var t = new Timer(0, this.output);
    t.start();
    t.reset();
    assert.ok(!t.running);
    assert.equal(t.startTime, 0);
    assert.equal(t.offset, 0);
    assert.equal(this.output.value, "0.0");
});

test("reset event", function(assert) {
    var done = assert.async();
    var t = new Timer(0, this.output);
    this.output.addEventListener("reset", function() {
        assert.push("Reset event fired");
        done();
    });
    t.reset();
});


{'fraction_non_alphanumeric': 0.1929853181076672, 'fraction_numerical': 0.01908646003262643, 'mean_word_length': 2.627810650887574, 'pattern_counts': {'":': 0, '<': 6, '<?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': '2440762', 'n_tokens_mistral': 2119, 'n_tokens_neox': 2028, 'n_words': 410}