jueves, 27 de noviembre de 2014

Algunas ideas del mundo del desarrollo de software

1._Pasa el tiempo muy rápido, tan rápido que en 2015 cumplo ocho años inmerso en la profesión de programador. Tras este tiempo he acumulado una serie de experiencias, algunas buenas y otras no tanto, junto a una serie de reflexiones que quiero poner en orden en este artículo. [más]

2._El programador es una especie más que intenta sobrevivir en este mundo. El medio en el que un programador nace, crece y muere cambia constantemente y a distintas velocidades. La selección natural se ha convertido en un proceso que en el caso de los programadores se agudiza y muchos individuos optan por la evolución como medio de supervivencia en un sector que sufre cataclismos de forma cíclica. [más]

miércoles, 26 de noviembre de 2014

Remove numbers in an array using gulp, mocha and expect

This last weekend, Iwas at codemotion 2014. In one  of the sessions, the speaker spoke about gulp. He said that it will be the standard tool for web developer. So I´ve done a little kata (remove a number in an array) with expect.js, mocha and gulp in javascript. The code lives here

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]);
  });
});