The gulpfile.js
var gulp = require('gulp'), jshint = require('gulp-jshint'), mocha = require('gulp-mocha'); gulp.task('jshint', function(){ gulp.src('source/*.js') jshint.reporter('default'); }); gulp.task('mocha', function () { gulp.src('test/*.js') .pipe(mocha({ reporter: 'list' })) .on('error', function(err){ console.log(err.message); this.emit('end'); }); }); gulp.task('watch', function () { gulp.watch('source/*.js', function(){ gulp.start('mocha'); }); gulp.watch('test/*.js', function(){ gulp.start('mocha'); }); }); gulp.task('default', function() { gulp.start('jshint', 'watch'); });
The System Under Test:
function removeElementInArray(number, vector){ if(vector == []){ return vector; } var result = []; var head; for(var position = 0; position < vector.length; position++){ head = vector[position]; if(head != number){ result.push(head); } } return result; } exports.remove = removeElementInArray;
And the tests:
var sut = require("../source/sut.js"), expect = require("expect.js"); describe("Remove a number in an array thought functional way using TDD", function(){ it("Given empty array then return empty array", function(){ expect(sut.remove(2, [])).to.eql([]); }); it("Given array with one element and 0 positions then return the same array", function(){ expect(sut.remove(2, [2])).to.eql([]); }); it("Given array with two numbers and number then return array without the number in the array", function(){ expect(sut.remove(1, [1,2])).to.eql([2]); }); it("Given array and positions then return rotated array without the number", function(){ expect(sut.remove(3, [3,2,3,4])).to.eql([2,4]); }); });
No hay comentarios:
Publicar un comentario