jsPsych/tests/datacollection.test.js
2016-12-15 22:18:22 -05:00

30 lines
800 B
JavaScript

require('../jspsych.js');
var data = [
{rt: 100},
{rt: 200},
{rt: 300},
{rt: 400},
{rt: 500}
];
jsPsych.data._customInsert(data);
describe('DataCollection', function(){
test('#mean', function(){
expect(jsPsych.data.getData().select('rt').mean()).toBe(300);
});
test('#count', function(){
expect(jsPsych.data.getData().select('rt').count()).toBe(5);
});
test('#sd', function(){
expect(jsPsych.data.getData().select('rt').sd()).toBe(Math.sqrt((Math.pow(200,2)+Math.pow(100,2)+Math.pow(100,2)+Math.pow(200,2))/5));
});
test('#median', function(){
expect(jsPsych.data.getData().select('rt').median()).toBe(300);
});
test('#subset', function(){
expect(jsPsych.data.getData().select('rt').subset(function(x){ return x > 300; }).count()).toBe(2);
})
});