<commit_before>var expect = require('chai').expect;
var elasticSearch = require('elasticsearch');
var Technologies = require('../server/technologies');
var initializeIndices = require('../distribution/initializeIndices');


var host = 'localhost:9200';
var index = 'relations_test';

var client = new elasticSearch.Client({
    host: host
});

var technologies = new Technologies(host, index);

var createRelation = function (t1, t2, v) {
    var data = function (t1, t2, v, plus) {
        return {
            index: index,
            type: "relations",
            id: t1 + "_" + t2 + "_" + plus,
            body: {
                t1: t1,
                t2: t2,
                v: v,
                plus: plus
            }
        };
    };

    return client.index(data(t1, t2, v, true))
        .then( function () { return client.index(data(t1, t2, v, false)); })
        .then( function () { return client.indices.refresh( { index: index, force: true }); });
};

describe('Relations Index', function () {

    beforeEach(function (done) {
        initializeIndices(host, index, function () {
            done();
        });
    });

    afterEach(function (done) {
        client.indices.delete({ index: index }, function () {
            done();
        });
    });

    it('should find only positive values when no avoid specified', function (done) {
        // given
        createRelation('java', 'spring', 1000)

            // when
            .then(function () { return technologies.getSuggestionsRaw(['java'], []) })

            // then
            .then(function (results) {
                console.log(results.aggregations.rel.buckets);
                var buckets = results.aggregations.rel.buckets;

                expect(buckets).to.have.length(1);
                expect(buckets[0].key).to.eql('spring');
                expect(buckets[0].doc_count).to.eql(1);
                expect(buckets[0].total.value).to.eql(1000);

                done();
            });
    });

});<commit_msg>Add test for decreasing value<commit_after>var expect = require('chai').expect;
var elasticSearch = require('elasticsearch');
var Technologies = require('../server/technologies');
var initializeIndices = require('../distribution/initializeIndices');


var host = 'localhost:9200';
var index = 'relations_test';

var client = new elasticSearch.Client({
    host: host
});

var technologies = new Technologies(host, index);

var createRelation = function (t1, t2, v) {
    var data = function (t1, t2, v, plus) {
        return {
            index: index,
            type: "relations",
            id: t1 + "_" + t2 + "_" + plus,
            body: {
                t1: t1,
                t2: t2,
                v: v,
                plus: plus
            }
        };
    };

    return client.index(data(t1, t2, v, true))
        .then( function () { return client.index(data(t1, t2, -v, false)); })
        .then( function () { return client.indices.refresh( { index: index, force: true }); });
};

describe('Relations Index', function () {

    beforeEach(function (done) {
        initializeIndices(host, index, function () {
            done();
        });
    });

    afterEach(function (done) {
        client.indices.delete({ index: index }, function () {
            done();
        });
    });

    it('should find only positive values when no avoid specified', function (done) {
        // given
        createRelation('c#', 'linq', 500)
            .then(createRelation('java', 'spring', 1000))

            // when
            .then(function () { return technologies.getSuggestionsRaw(['java'], []) })

            // then
            .then(function (results) {
                var buckets = results.aggregations.rel.buckets;

                expect(buckets).to.have.length(1);
                expect(buckets[0].key).to.eql('spring');
                expect(buckets[0].doc_count).to.eql(1);
                expect(buckets[0].total.value).to.eql(1000);

                done();
            });
    });

    it('decrease value if avoid specified', function (done) {
        // given
        createRelation('java', 'spring', 1000)
            .then(createRelation('scala', 'spring', 700))

            // when
            .then(function () { return technologies.getSuggestionsRaw(['java'], ['scala']) })

            // then
            .then(function (results) {
                var buckets = results.aggregations.rel.buckets;

                expect(buckets).to.have.length(1);
                expect(buckets[0].key).to.eql('spring');
                expect(buckets[0].doc_count).to.eql(2);
                expect(buckets[0].total.value).to.eql(300);

                done();
            });
    });

});
{'fraction_non_alphanumeric': 0.15269271383315733, 'fraction_numerical': 0.01689545934530095, 'mean_word_length': 1.8895668090298963, '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': '2956589', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1312, 'n_words': 290}