Code coverage report for lib/trap.js

Statements: 76.47% (13 / 17)      Branches: 50% (4 / 8)      Functions: 100% (2 / 2)      Lines: 76.47% (13 / 17)      Ignored: none     

All files » lib/ » trap.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                          1 1             1 2 8   2     2     2     2         2       1 10     1  
 
// Trap function with Fitness function signature
//
// Trap is a deceptive function that is used, concatenated, to test
// evolutionary algorithms. 
// @license GPL v3
// @package nodeo
// @author J. J. Merelo <jjmerelo@gmail.com>
 
// To avoid uncomprehensible radix complaint at charAt
/*jshint -W065 */
/*jshint smarttabs:true */
 
var functions = require('./functions');
var trap = exports;
 
// Class definition
// ```
// var trap = new Trap.trap( { l: 3, a: 1, b:2, z = 2})
// ```
//
function Trap( options ) {
    for ( var i in options ) {
	this[i] = options[i];
    }
    Iif ( !this.l ) {
	this.l = 3;
    }
    Iif ( !this.a ) {
	this.a = 1;
    }
    Iif ( !this.b ) {
	this.l = 2;
    }
    Iif ( !this.z ) {
	this.a = this.l-1;
    }
 
    // Methods
    this.apply = apply;
}
 
// Applies trap function to chromosome using instance values
function apply( chromosome ){
    return functions.ltrap(chromosome, this.l, this.a, this.b, this.z);    
}
 
trap.Trap = Trap;