<commit_before>// MOT = message oriented testing

var _ = require('underscore');
var s = require('../../public/javascripts/s');
var assert = require('assert');

// TODO: check that results are received in order as their events
// right now the event arguments are just a set, not a vector
var expect = function(emitter, callback /* , event1...n */) {
    var events = _.flatten(_.rest(arguments, 2));
    var results = [];

    var trap = function() {
        _.each(arguments, function(val) { results.push(val); });
        if (results.length === events.length) {
            callback(null, results);
        }
    };

    var that = this;
    _.each(events, function(event) {
        emitter.on(event, trap);
    });
};


// TODO: work with var args instead of requiring a vector as an arg
var verify = function() {
    var expected = _.toArray(arguments);

    return function(err, actual) {
        assert.equal(err, undefined);

        var ok = true;
        for (var i = 0; i < arguments.length; i++) {
            if (expected[i] !== actual[i]) {
                ok = false;
                break;
            }
        }

        if (!ok) {
            s.debug_inspect({'actual': actual, 'expected': expected});
        }
        assert.ok(ok);
    };
};

exports.verify = verify;<commit_msg>always expect the values to be passed as an array... hard to programmatically emit variable args otherwise<commit_after>// MOT = message oriented testing

var _ = require('underscore');
var s = require('../../public/javascripts/s');
var assert = require('assert');

// TODO: check that results are received in order as their events
// right now the event arguments are just a set, not a vector
var expect = function(emitter, callback /* , event1...n */) {
    var events = _.flatten(_.rest(arguments, 2));
    var results = [];

    var trap = function() {
        _.each(arguments, function(val) { results.push(val); });
        if (results.length === events.length) {
            callback(null, results);
        }
    };

    var that = this;
    _.each(events, function(event) {
        emitter.on(event, trap);
    });
};


var verify = function() {
    var expected = _.toArray(arguments);

    return function(err, vals) {
        assert.equal(err, undefined);
        var actual = _(vals).flatten();

        var ok = true;
        for (var i = 0; i < arguments.length; i++) {
            if (expected[i] !== actual[i]) {
                ok = false;
                break;
            }
        }

        if (!ok) {
            s.debug_inspect({'actual': actual, 'expected': expected});
        }
        assert.ok(ok);
    };
};

exports.verify = verify;
{'fraction_non_alphanumeric': 0.14596622889305816, 'fraction_numerical': 0.00225140712945591, 'mean_word_length': 2.170035671819263, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7278284', 'n_tokens_mistral': 774, 'n_tokens_neox': 741, 'n_words': 233}