var assert = require('assert');
var oftype = require('oftype');

function test(config) {
    var inputs = config.inputs;
    var outputs = config.outputs;
    var transform = config.transform;
    var validate = config.validate;
    var groupName = config.groupName;
    var caseName = config.caseName;

    if (inputs && outputs && transform && validate) {
        if (!groupName) {
            testCase(caseName, inputs, outputs, transform, validate);
        } else {
            describe(groupName, function() {
                testCase(caseName, inputs, outputs, transform, validate);
            });
        }
    };
}

function testCase(caseName, inputs, outputs, transform, validate) {
    inputs.forEach(function(input, index) {
        var name = composeCaseName(caseName, index, inputs, outputs);
        it(name, function() {
            var result = transform(input);
            assert.ok(validate(outputs[index], result));
        });
    });
}

function composeCaseName(caseName, index, inputs, outputs) {
    if (!caseName) {
        return 'test case #' + index;
    } else if(oftype(caseName, String)) {
        return caseName;
    } else if (caseName instanceof Function) {
        return caseName(index, inputs, outputs);
    }
}

exports.test = test;

@@ -220,16 +220,35 @@
 validate
+ %7C%7C defaultValidate
 ;%0A    va
@@ -1265,16 +1265,95 @@
    %7D%0A%7D%0A%0A
+function defaultValidate(expected, actual) %7B%0A    return expected == actual;%0A%7D%0A%0A
 exports.

add default validation function