Skip to content

Commit 8c023d9

Browse files
t111joeyklee
authored andcommitted
Adding index_test.js to sentiment model (#649)
* Adding tests for sentiment. * Removing unnecessary console.log. * Removing unnecessary console.log. * remove inappropriate word.
1 parent 222fe06 commit 8c023d9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Sentiment/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class Sentiment {
4242
* @param {function} callback - Optional. A callback function that is called once the model has loaded. If no callback is provided, it will return a promise that will be resolved once the model has loaded.
4343
*/
4444
constructor(modelName, callback) {
45-
console.log('constructor');
4645
/**
4746
* Boolean value that specifies if the model has loaded.
4847
* @type {boolean}

src/Sentiment/index_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { sentiment } = ml5;
2+
3+
describe('Sentiment', ()=>{
4+
let model;
5+
6+
beforeAll(async () => {
7+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
8+
model = await sentiment('moviereviews').ready;
9+
});
10+
11+
it("Model should be ready",()=> expect(model.ready).toBeTruthy());
12+
13+
it("Happy has a sentiment score greater than 0.5", ()=>{
14+
expect(model.predict('Happy').score).toBeGreaterThan(0.5);
15+
});
16+
17+
it("Terrible has a sentiment score less than 0.5", ()=>{
18+
expect(model.predict('Terrible').score).toBeLessThan(0.5);
19+
});
20+
});

0 commit comments

Comments
 (0)