adding some unit-tests
https://github.com/thisandagain/sentiment
https://github.com/akumpf/sentiment/blob/patch-1/lib/index.js
https://github.com/akumpf/sentiment/commit/23407526a146efbfdd9929e9bd74462e65d52ada
https://github.com/thisandagain/sentiment/pull/16
And, of course, I discover that the implementation is.... sub-optimal.
But not non-existant.
git clone https://github.com/akumpf/sentiment git checkout patch-1
then, once the below is added to sync_negative.js
node_modules\tap\bin\tap.js test\unit\*.js
or
node_modules\tap\bin\tap.js test\unit\sync_negative.js
var normalNegative = 'Cats are stupid.';
var negationNegative = 'Cats are not stupid.'; // introduces negation keyword
var normalResult = sentiment(normalNegative);
var negationResult = sentiment(negationNegative);
t.type(normalResult, 'object');
t.equal(normalResult.score, -2);
t.equal(normalResult.comparative, -0.6666666666666666);
t.equal(normalResult.tokens.length, 3);
t.equal(normalResult.words.length, 1);
t.type(negationResult, 'object');
t.equal(negationResult.score, 2);
t.equal(negationResult.comparative, 0.5);
t.equal(negationResult.tokens.length, 4);
t.equal(negationResult.words.length, 1);
var dataset = 'Hey you non-worthless scumbag';
var result = sentiment(dataset);
t.type(result, 'object');
t.equal(result.score, -4);
t.equal(result.comparative, -1);
t.equal(result.tokens.length, 4);
t.equal(result.words.length, 1);
t.equal(result.positive.length, 0);
t.equal(result.negative.length, 1);
dataset = 'Hey you non worthless scumbag';
result = sentiment(dataset);
t.type(result, 'object');
t.equal(result.score, -2);
t.equal(result.comparative, -0.4);
t.equal(result.tokens.length, 5);
t.equal(result.words.length, 2);
t.equal(result.positive.length, 1);
t.equal(result.negative.length, 1);
t.end();
});
Recent Comments