<commit_before>/*jslint node: true, passfail: false */

const expect = require('chai').expect;
const debug = require('debug')('jubatus-node-client:test:burst');
const testUtil = require('./util');
const jubatus = require('../index.js');

let server;
let client;

before(done => {
    const command = 'jubaburst', config = 'burst_config.json';
    testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
        server = serverProcess;
        client = new jubatus.burst.client.Burst(port, 'localhost');
        done();
    }).catch(done);
});

after(done => {
    client.getClient().close();
    server.kill();
    done();
});

describe('burst#add_documents', () => {
    it('add_documents', done => {
        const keyword = 'foo';
        const keywordParams  = new jubatus.burst.types.KeywordWithParams(keyword, 1.2, 0.3);
        const document = new jubatus.burst.types.Document(1.2, 'foobar');
        const documents = [ document ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);
            
            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
        }).then(([ result ]) => {
            debug(result);
            expect(result).to.be.a('number');
            expect(result).to.equal(1);
            done();
        }).catch(done);
    });
});

describe('burst#get_result', () => {
    it('get_result', done => {
        const keyword = 'foo';
        const keywordParams  = [ keyword, 1.001, 0.001 ];
        const documents = [ [ 0, 'foo' ], [ 0, 'bar' ], [ 0, 'baz' ] ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
        }).then(([ result ]) => {
            expect(result).to.equal(3);

            return client.getResult(keyword);
        }).then(([ result ]) => {
            debug(result);
            expect(result).to.be.a('Window')
                .and.to.deep.equal(jubatus.burst.types.Window.fromTuple([ -20, [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 3, 1, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] ]));
            done();
        }).catch(done);
    });
});

describe('burst#get_all_bursted_results', () => {
    it('get_all_bursted_results', done => {
        const keyword = 'foo';
        const keywordParams  = [ keyword, 1.001, 0.001 ];
        const documents = [ [ 0, 'foo' ], [ 1, 'bar' ], [ 2, 'baz' ] ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);<commit_msg>Update test/burst.js<commit_after>/*jslint node: true, passfail: false */

const expect = require('chai').expect;
const debug = require('debug')('jubatus-node-client:test:burst');
const testUtil = require('./util');
const jubatus = require('../index.js');

let server;
let client;

before(done => {
    const command = 'jubaburst', config = 'burst_config.json';
    testUtil.createServerProcess(command, config).then(([ port, serverProcess ]) => {
        server = serverProcess;
        client = new jubatus.burst.client.Burst(port, 'localhost');
        done();
    }).catch(done);
});

after(done => {
    client.getClient().close();
    server.kill();
    done();
});

describe('burst#add_documents', () => {
    it('add_documents', done => {
        const keyword = 'foo';
        const keywordParams  = new jubatus.burst.types.KeywordWithParams(keyword, 1.2, 0.3);
        const document = new jubatus.burst.types.Document(1.2, 'foobar');
        const documents = [ document ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);
            
            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
        }).then(([ result ]) => {
            debug(result);
            expect(result).to.be.a('number');
            expect(result).to.equal(1);
            done();
        }).catch(done);
    });
});

describe('burst#get_result', () => {
    it('get_result', done => {
        const keyword = 'foo';
        const keywordParams  = [ keyword, 1.001, 0.001 ];
        const documents = [ [ 0, 'foo' ], [ 0, 'bar' ], [ 0, 'baz' ] ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
        }).then(([ result ]) => {
            expect(result).to.equal(3);

            return client.getResult(keyword);
        }).then(([ result ]) => {
            debug(result);
            expect(result).to.be.a('Window')
                .and.to.deep.equal(jubatus.burst.types.Window.fromTuple([ -20, [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 3, 1, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] ]));
            done();
        }).catch(done);
    });
});

describe('burst#get_result_at', () => {
    it('get_result_at', done => {
        const keyword = 'foo';
        const keywordParams = new jubatus.burst.types.KeywordWithParams(keyword, 1.001, 0.001);
        const documents = [
            new jubatus.burst.types.Document(0, 'foo'),
            new jubatus.burst.types.Document(3, 'bar'),
            new jubatus.burst.types.Document(6, 'baz')
        ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
        }).then(([ result ]) => {
            expect(result).to.equal(3);

            return client.getResultAt(keyword, 0);
        }).then(([ result ]) => {
            debug(result);
            expect(result).to.be.a('Window')
                .and.to.deep.equal(jubatus.burst.types.Window.fromTuple([ -20, [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 3, 1, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] ]));
            done();
        }).catch(done);
    });
});

describe('burst#get_all_bursted_results', () => {
    it('get_all_bursted_results', done => {
        const keyword = 'foo';
        const keywordParams  = [ keyword, 1.001, 0.001 ];
        const documents = [ [ 0, 'foo' ], [ 1, 'bar' ], [ 2, 'baz' ] ];
        client.clear().then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addKeyword(keywordParams);
        }).then(([ result ]) => {
            expect(result).to.equal(true);

            return client.addDocuments(documents);
{'fraction_non_alphanumeric': 0.18911954187544738, 'fraction_numerical': 0.017752326413743736, 'mean_word_length': 2.2134314627414904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '2586528', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2128, 'n_words': 394}