<commit_before>/*
 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
 */

var assert = require('assert');
var uuid = require('node-uuid');
var filter = require('../../lib/algorithms/soft-filter-recent-servers.js');



var log = { trace: function () {}, debug: function () {} };

var givenServers = [];
for (var ii = 0; ii < 12; ii++) {
    givenServers.push({ uuid: uuid() });
}



exports.filterRecentServers_no_prior_servers =
function (t) {
    var expectedServers = givenServers;
    var state = {};

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(state, { recent_servers: {} });

    t.done();
};



exports.filterRecentServers_some_prior_servers =
function (t) {
    var now = +new Date();
    var expectedServers  = givenServers.slice(0, 11);
    var oldServerUuid    = givenServers[11].uuid;
    var tooOldServerUuid = givenServers[10].uuid;

    var state = { recent_servers: {} };
    state.recent_servers[oldServerUuid   ] = now - 4000;
    state.recent_servers[tooOldServerUuid] = now - 6000;

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(Object.keys(state), ['recent_servers']);
    t.deepEqual(Object.keys(state.recent_servers), [oldServerUuid]);
    t.equal(state.recent_servers[oldServerUuid], now - 4000);

    t.done();
};



exports.filterRecentServers_more_prior_servers =
function (t) {
    var now = +new Date();
    var expectedServers = givenServers.slice(3, givenServers.length);

    var state = { recent_servers: {} };
    for (var i = 0; i !== givenServers.length - 1; i++) {
        var serverUuid = givenServers[i].uuid;
        var timestamp  = now - (i + 0.5) * 1000;
        state.recent_servers[serverUuid] = timestamp;
    }

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(Object.keys(state), ['recent_servers']);

    t.equal(Object.keys(state.recent_servers).length, 5);
    for (i = 0; i < 5; i++) {
        serverUuid = givenServers[i].uuid;
        timestamp  = now - (i + 0.5) * 1000;
        t.deepEqual(state.recent_servers[serverUuid], timestamp);
    }

    t.done();
};



exports.filterRecentServers_with_no_prior_servers =
function (t) {
    var state = {};

    var filteredServers = filter.run(log, state, []);

    t.equal(filteredServers.length, 0);
    t.deepEqual(state, { recent_servers: {} });

    t.done();
};



exports.post =
function (t) {
    var server = givenServers[0];
    var state  = { recent_servers: {} };
    var now    = +new Date();

    filter.post(log, state, server);

    t.equal(Object.keys(state.recent_servers).length, 1);
    t.ok(state.recent_servers[server.uuid] <= now);

    t.done();
};<commit_msg>DAPI-58 - fix wrong conditional used in test.<commit_after>/*
 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
 */

var assert = require('assert');
var uuid = require('node-uuid');
var filter = require('../../lib/algorithms/soft-filter-recent-servers.js');



var log = { trace: function () {}, debug: function () {} };

var givenServers = [];
for (var ii = 0; ii < 12; ii++) {
    givenServers.push({ uuid: uuid() });
}



exports.filterRecentServers_no_prior_servers =
function (t) {
    var expectedServers = givenServers;
    var state = {};

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(state, { recent_servers: {} });

    t.done();
};



exports.filterRecentServers_some_prior_servers =
function (t) {
    var now = +new Date();
    var expectedServers  = givenServers.slice(0, 11);
    var oldServerUuid    = givenServers[11].uuid;
    var tooOldServerUuid = givenServers[10].uuid;

    var state = { recent_servers: {} };
    state.recent_servers[oldServerUuid   ] = now - 4000;
    state.recent_servers[tooOldServerUuid] = now - 6000;

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(Object.keys(state), ['recent_servers']);
    t.deepEqual(Object.keys(state.recent_servers), [oldServerUuid]);
    t.equal(state.recent_servers[oldServerUuid], now - 4000);

    t.done();
};



exports.filterRecentServers_more_prior_servers =
function (t) {
    var now = +new Date();
    var expectedServers = givenServers.slice(3, givenServers.length);

    var state = { recent_servers: {} };
    for (var i = 0; i !== givenServers.length - 1; i++) {
        var serverUuid = givenServers[i].uuid;
        var timestamp  = now - (i + 0.5) * 1000;
        state.recent_servers[serverUuid] = timestamp;
    }

    var filteredServers = filter.run(log, state, givenServers);

    t.deepEqual(filteredServers, expectedServers);
    t.deepEqual(Object.keys(state), ['recent_servers']);

    t.equal(Object.keys(state.recent_servers).length, 5);
    for (i = 0; i < 5; i++) {
        serverUuid = givenServers[i].uuid;
        timestamp  = now - (i + 0.5) * 1000;
        t.deepEqual(state.recent_servers[serverUuid], timestamp);
    }

    t.done();
};



exports.filterRecentServers_with_no_prior_servers =
function (t) {
    var state = {};

    var filteredServers = filter.run(log, state, []);

    t.equal(filteredServers.length, 0);
    t.deepEqual(state, { recent_servers: {} });

    t.done();
};



exports.post =
function (t) {
    var server = givenServers[0];
    var state  = { recent_servers: {} };
    var now    = +new Date();

    filter.post(log, state, server);

    t.equal(Object.keys(state.recent_servers).length, 1);
    t.ok(state.recent_servers[server.uuid] >= now);

    t.done();
};
{'fraction_non_alphanumeric': 0.15316101990918618, 'fraction_numerical': 0.016765630457562, 'mean_word_length': 3.415574402467232, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, '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': '7197', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1918, 'n_words': 386}