Skip to content

Commit 535c5b1

Browse files
committed
refactor: adds non mocked test for charRnn
1 parent 30d6b5f commit 535c5b1

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/CharRNN/index_test.js renamed to src/CharRNN/__tests__/CharRNN.test.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,59 @@
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
55

6-
const { charRNN } = ml5;
6+
// TODO: Mock network requests -- local test run took roughly ~8 - ~12.2s!!
77

8-
const RNN_MODEL_URL = 'https://raw.githubusercontent.com/ml5js/ml5-data-and-models/master/models/lstm/woolf';
8+
import charRNN from "../index";
9+
10+
const RNN_MODEL_URL =
11+
"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/master/models/lstm/woolf";
912

1013
const RNN_MODEL_DEFAULTS = {
1114
cellsAmount: 2,
12-
vocabSize: 223
15+
vocabSize: 223,
1316
};
1417

1518
const RNN_DEFAULTS = {
16-
seed: 'a',
19+
seed: "a",
1720
length: 20,
1821
temperature: 0.5,
19-
stateful: false
20-
}
22+
stateful: false,
23+
};
2124

2225
const RNN_OPTIONS = {
23-
seed: 'the meaning of pizza is: ',
26+
seed: "the meaning of pizza is: ",
2427
length: 10,
25-
temperature: 0.7
26-
}
28+
temperature: 0.7,
29+
};
2730

28-
describe('charRnn', () => {
31+
describe("charRnn", () => {
2932
let rnn;
3033

3134
beforeAll(async () => {
32-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; // set extra long interval due to issues with CharRNN generation time
33-
rnn = await charRNN(RNN_MODEL_URL, undefined);
35+
jest.testTimeout = 20000; // set extra long interval due to issues with CharRNN generation time
36+
rnn = await charRNN(RNN_MODEL_URL, undefined);
3437
});
3538

3639
// it('loads the model with all the defaults', async () => {
3740
// expect(rnn.cellsAmount).toBe(RNN_MODEL_DEFAULTS.cellsAmount);
3841
// expect(rnn.vocabSize).toBe(RNN_MODEL_DEFAULTS.vocabSize);
3942
// });
4043

41-
describe('generate', () => {
42-
it('instantiates an rnn with all the defaults', async () => {
44+
describe("generate", () => {
45+
it("instantiates an rnn with all the defaults", async () => {
4346
expect(rnn.ready).toBeTruthy();
4447
expect(rnn.defaults.seed).toBe(RNN_DEFAULTS.seed);
4548
expect(rnn.defaults.length).toBe(RNN_DEFAULTS.length);
4649
expect(rnn.defaults.temperature).toBe(RNN_DEFAULTS.temperature);
4750
expect(rnn.defaults.stateful).toBe(RNN_DEFAULTS.stateful);
4851
});
49-
50-
it('Should generate content that follows default options if given an empty object', async() => {
52+
53+
it("Should generate content that follows default options if given an empty object", async () => {
5154
const result = await rnn.generate({});
5255
expect(result.sample.length).toBe(20);
5356
});
5457

55-
it('generates content that follows the set options', async() => {
58+
it("generates content that follows the set options", async () => {
5659
const result = await rnn.generate(RNN_OPTIONS);
5760
expect(result.sample.length).toBe(RNN_OPTIONS.length);
5861
});

0 commit comments

Comments
 (0)