<commit_before>/**
 * Created by szmurlor on 08.06.15.
 */

var imax = 2;
var imaxe = 10;
var imaxne = 10;
var imaxkn = 10;


var http = require('http');
var fs = require('fs');

var options_push = {
    host: 'localhost',
    path: '/push',
    port: '4730',
    method: 'POST',
    headers: { 'Content-Type': 'application/json' }
};

var options_search = {
    host: 'localhost',
    path: '/search',
    port: '4730',
    method: 'GET',
    headers: { 'Content-Type': 'application/json' }
};


exports.testKrotki = function(test){
    fs.readFile('tekst-krotki.txt', 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }

        var post_data = JSON.stringify({
            // filename: "reymont-chlopi-zima.txt",
            filename: "tekst-krotki.txt",
            data: data,
            folder: "/home/data/example"
        });

        var str = "";
        var req = http.request(options_push, function(res) {
            res.on('data', function(chunk) {
                str += chunk;
            });
            res.on('end', function() {
               //console.log(str);
               test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");
               test.done();
            });
        });
        req.write(post_data);
        req.end();
    });
};

exports.testDlugi = function(test){
    var i = 0;

    function doTest() {
        fs.readFile('reymont-chlopi-zima.txt', 'utf8', function (err, data) {
            if (err) {
                return console.log(err);
            }

            var post_data = JSON.stringify({
                // filename: "reymont-chlopi-zima.txt",
                filename: "reymont-chlopi-zima-"+ i +".txt",
                data: data,
                folder: "/home/data/example_" + i
            });

            var str = "";
            var req = http.request(options_push, function (res) {
                res.on('data', function (chunk) {
                    str += chunk;
                });
                res.on('end', function () {
                    //console.log(str);
                    test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");

                    if (i++ < imax)
                        doTest();
                    else
                        test.done();
                });
            });
            req.write(post_data);
            req.end();
        });
    };
    doTest();
};

exports.testSearchNoExists = function(test){
    doSearch(test, 0, "jesiennykol", true, false);
};


exports.testSearchExists = function(test){
    doSearch(test, 0, "0011223344", false, true, function (test, response) {
        // test.ok(response.indexOf('{"pos":7997,"line":56}') >= 0, "Nie odnaleziono ciągu znaków 0011223344!");
        test.ok(response.indexOf('7997') >= 0, "Nie odnaleziono ciągu znaków 0011223344!");
    });
};

exports.testKrotkiN = function(test){
    var i = 0;

    function doKrotoki() {
        fs.readFile('tekst-krotki.txt', 'utf8', function (err, data) {
            if (err) {
                return console.log(err);
            }

            var post_data = JSON.stringify({
                // filename: "reymont-chlopi-zima.txt",
                filename: "tekst-krotki" + i +".txt",
                data: data,
                folder: "/home/"+i+"/example"
            });

            var str = "";
            var req = http.request(options_push, function(res) {
                res.on('data', function(chunk) {
                    str += chunk;
                });
                res.on('end', function() {
                    //console.log(str);
                    test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");

                    if (i++ < imaxkn)
                        doKrotoki();
                    else
                        test.done();
                });<commit_msg>iPorawione content-length<commit_after>/**
 * Created by szmurlor on 08.06.15.
 */

var imax = 2;
var imaxe = 10;
var imaxne = 10;
var imaxkn = 10;


var http = require('http');
var fs = require('fs');

var options_push = {
    //host: 'localhost',
    host: '10.146.51.117',
    path: '/push',
    // port: '4730',
    port: '8000',
    method: 'POST',
    headers: { 'Content-Type': 'application/json; charset=utf-8' }
};

var options_search = {
    //host: 'localhost',
    host: '10.146.51.117',
    path: '/search',
    //port: '4730',
    port: '8000',
    method: 'GET',
    headers: { 'Content-Type': 'application/json; charset=utf-8' }
};


exports.testKrotki = function(test){
    fs.readFile('tekst-krotki.txt', 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }

        var post_data = JSON.stringify({
            // filename: "reymont-chlopi-zima.txt",
            filename: "tekst-krotki.txt",
            data: data,
            folder: "/home/data/example"
        });

        var str = "";
	options_push.headers['Content-length'] = post_data.length;
        var req = http.request(options_push, function(res) {
            res.on('data', function(chunk) {
                str += chunk;
            });
            res.on('end', function() {
               //console.log(str);
               test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");
               test.done();
            });
        });
        req.write(post_data);
        req.end();
    });
};

exports.testDlugi = function(test){
    var i = 0;

    function doTest() {
        fs.readFile('reymont-chlopi-zima.txt', 'utf8', function (err, data) {
            if (err) {
                return console.log(err);
            }

            var post_data = JSON.stringify({
                // filename: "reymont-chlopi-zima.txt",
                filename: "reymont-chlopi-zima-"+ i +".txt",
                data: data,
                folder: "/home/data/example_" + i
            });

            var str = "";
	    options_push.headers['Content-length'] = post_data.length;
            var req = http.request(options_push, function (res) {
                res.on('data', function (chunk) {
                    str += chunk;
                });
                res.on('end', function () {
                    //console.log(str);
                    test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");

                    if (i++ < imax)
                        doTest();
                    else
                        test.done();
                });
            });
            req.write(post_data);
            req.end();
        });
    };
    doTest();
};

exports.testSearchNoExists = function(test){
    doSearch(test, 0, "jesiennykol", true, false);
};


exports.testSearchExists = function(test){
    doSearch(test, 0, "0011223344", false, true, function (test, response) {
        // test.ok(response.indexOf('{"pos":7997,"line":56}') >= 0, "Nie odnaleziono ciągu znaków 0011223344!");
        test.ok(response.indexOf('7997') >= 0, "Nie odnaleziono ciągu znaków 0011223344!");
    });
};

exports.testKrotkiN = function(test){
    var i = 0;

    function doKrotoki() {
        fs.readFile('tekst-krotki.txt', 'utf8', function (err, data) {
            if (err) {
                return console.log(err);
            }

            var post_data = JSON.stringify({
                // filename: "reymont-chlopi-zima.txt",
                filename: "tekst-krotki" + i +".txt",
                data: data,
                folder: "/home/"+i+"/example"
            });

            var str = "";
	    options_push.headers['Content-length'] = post_data.length;
            var req = http.request(options_push, function(res) {
                res.on('data', function(chunk) {
                    str += chunk;
                });
                res.on('end', function() {
                    //console.log(str);
                    test.equal(str, '<p>OK</p>', "Niewłaściwa odpowiedź.");

                    if (i++ < imaxkn)
                        doKrotoki();
                    else
                        test.done();
                });
{'fraction_non_alphanumeric': 0.15915580384854128, 'fraction_numerical': 0.02110490378646803, 'mean_word_length': 1.4902627511591964, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6911004', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2455, 'n_words': 483}