Skip to content

Commit

Permalink
[TESTS] input argument validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Mar 27, 2015
1 parent 18823fd commit 5089841
Show file tree
Hide file tree
Showing 3 changed files with 426 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ TODO
- dido for prediction, how to handle? skip over...
9. check against `len < 2`!!!
- only a single data point; unless pass through (0,0), then cannot model!
- should it return `null` or error?
10.
224 changes: 223 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,228 @@ describe( 'compute-linear-regression', function tests() {
expect( lr ).to.be.a( 'function' );
});

it( 'should do something' );
it( 'should throw an error if not provided a data array', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
{},
function(){}
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( value );
};
}
});

it( 'should throw an error if not provided an array or an options object as a second argument', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
function(){}
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [[1,1],[2,2]], value );
};
}
});

it( 'should throw an error if provided a dependent variable which is not an array', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
{},
function(){}
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2,3], value, {} );
};
}
});

it( 'should throw an error if provided an options argument which is not an object', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
[],
function(){}
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], value );
};
}
});

it( 'should throw an error if the independent and dependent variable arrays are of unequal length', function test() {
expect( foo ).to.throw( Error );
function foo() {
lr( [1,2], [1,2,3] );
}
});

it( 'should throw an error if provided an accessors option which is not an object', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
function(){},
[]
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], {
'accessors': value
});
};
}
});

it( 'should throw an error if provided an x-accessor which is not a function', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
{},
[]
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], {
'accessors': {
'x': value
}
});
};
}
});

it( 'should throw an error if provided a y-accessor which is not a function', function test() {
var values = [
'5',
5,
NaN,
null,
undefined,
true,
{},
[]
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], {
'accessors': {
'y': value
}
});
};
}
});

it( 'should throw an error if provided a non-numeric slope', function test() {
var values = [
'5',
function(){},
NaN,
null,
undefined,
true,
{},
[]
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], {
'slope': value
});
};
}
});

it( 'should throw an error if provided a non-numeric intercept', function test() {
var values = [
'5',
function(){},
NaN,
null,
undefined,
true,
{},
[]
];

for ( var i = 0; i < values.length; i++ ) {
expect( badValue( values[i] ) ).to.throw( TypeError );
}
function badValue( value ) {
return function() {
lr( [1,2], [1,2], {
'intercept': value
});
};
}
});

it( 'should return a model object', function test() {
assert.isObject( lr( [1,2], [1,2] ) );
});

it( 'should...' );

});

0 comments on commit 5089841

Please sign in to comment.