<commit_before>var expect = require('chai').expect;

var ESS = require('../ExponentialSmoothingStream');
var strategies = require('../lib/strategies');

describe('exponential-smoothing-stream', function() {
    describe('stream', function() {
        it('should', function(done) {
            var a = new ESS({
                smoothingFactor: 0.5
            });

            var valueList = [];

            a.write(2);
            a.write(2);
            a.write(3);
            a.write(2);
            a.write(1);

            a.end();

            a.on('data', function(data) {
                valueList.push(data);
            });

            a.on('end', function() {
                expect(valueList).to.deep.equal([2, 2, 2.5, 2.25, 1.625]);
                done();
            });
        });
    });

    describe('initial strategies', function() {
        describe('first', function() {
            it('should return the first value', function() {
                var a = new strategies.InitialStrategyFirst();

                expect(a.determine(1337)).to.equal(1337);
            });
        });

        describe('fixed value', function() {
            it('should return a fixed value', function() {
                var a = new strategies.InitialStrategyFixed(1);

                expect(a.determine(100)).to.equal(1);
            });

            it('should throw on NAN value', function() {
                expect(function() {
                    new strategies.InitialStrategyFixed('foobar');
                }).to.throw();
            });
        });<commit_msg>added error test<commit_after>var expect = require('chai').expect;

var ESS = require('../ExponentialSmoothingStream');
var strategies = require('../lib/strategies');

describe('exponential-smoothing-stream', function() {
    describe('stream', function() {
        it('should', function(done) {
            var a = new ESS({
                smoothingFactor: 0.5
            });

            var valueList = [];

            a.write(2);
            a.write(2);
            a.write(3);
            a.write(2);
            a.write(1);

            a.end();

            a.on('data', function(data) {
                valueList.push(data);
            });

            a.on('end', function() {
                expect(valueList).to.deep.equal([2, 2, 2.5, 2.25, 1.625]);
                done();
            });
        });

        it('should emit an error', function(done) {
            var a = new ESS();

            var valueList = [];

            a.on('data', function(data) {
                valueList.push(data);
            });

            a.on('end', function() {
                expect(true).to.be.false;
            });

            a.on('error', function() {
                expect(valueList).to.deep.equal([]);
                done();
            });

            a.write('foobar');
            a.end();
        });
    });

    describe('initial strategies', function() {
        describe('first', function() {
            it('should return the first value', function() {
                var a = new strategies.InitialStrategyFirst();

                expect(a.determine(1337)).to.equal(1337);
            });
        });

        describe('fixed value', function() {
            it('should return a fixed value', function() {
                var a = new strategies.InitialStrategyFixed(1);

                expect(a.determine(100)).to.equal(1);
            });

            it('should throw on NAN value', function() {
                expect(function() {
                    new strategies.InitialStrategyFixed('foobar');
                }).to.throw();
            });
        });
{'fraction_non_alphanumeric': 0.15581585399073822, 'fraction_numerical': 0.016889131026968127, 'mean_word_length': 1.4366290643662907, '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': '2430038', 'n_tokens_mistral': 1035, 'n_tokens_neox': 945, 'n_words': 185}