|
3 | 3 | // This software is released under the MIT License.
|
4 | 4 | // https://opensource.org/licenses/MIT
|
5 | 5 |
|
6 |
| -const { charRNN } = ml5; |
| 6 | +// TODO: Mock network requests -- local test run took roughly ~8 - ~12.2s!! |
7 | 7 |
|
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"; |
9 | 12 |
|
10 | 13 | const RNN_MODEL_DEFAULTS = {
|
11 | 14 | cellsAmount: 2,
|
12 |
| - vocabSize: 223 |
| 15 | + vocabSize: 223, |
13 | 16 | };
|
14 | 17 |
|
15 | 18 | const RNN_DEFAULTS = {
|
16 |
| - seed: 'a', |
| 19 | + seed: "a", |
17 | 20 | length: 20,
|
18 | 21 | temperature: 0.5,
|
19 |
| - stateful: false |
20 |
| -} |
| 22 | + stateful: false, |
| 23 | +}; |
21 | 24 |
|
22 | 25 | const RNN_OPTIONS = {
|
23 |
| - seed: 'the meaning of pizza is: ', |
| 26 | + seed: "the meaning of pizza is: ", |
24 | 27 | length: 10,
|
25 |
| - temperature: 0.7 |
26 |
| -} |
| 28 | + temperature: 0.7, |
| 29 | +}; |
27 | 30 |
|
28 |
| -describe('charRnn', () => { |
| 31 | +describe("charRnn", () => { |
29 | 32 | let rnn;
|
30 | 33 |
|
31 | 34 | 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); |
34 | 37 | });
|
35 | 38 |
|
36 | 39 | // it('loads the model with all the defaults', async () => {
|
37 | 40 | // expect(rnn.cellsAmount).toBe(RNN_MODEL_DEFAULTS.cellsAmount);
|
38 | 41 | // expect(rnn.vocabSize).toBe(RNN_MODEL_DEFAULTS.vocabSize);
|
39 | 42 | // });
|
40 | 43 |
|
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 () => { |
43 | 46 | expect(rnn.ready).toBeTruthy();
|
44 | 47 | expect(rnn.defaults.seed).toBe(RNN_DEFAULTS.seed);
|
45 | 48 | expect(rnn.defaults.length).toBe(RNN_DEFAULTS.length);
|
46 | 49 | expect(rnn.defaults.temperature).toBe(RNN_DEFAULTS.temperature);
|
47 | 50 | expect(rnn.defaults.stateful).toBe(RNN_DEFAULTS.stateful);
|
48 | 51 | });
|
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 () => { |
51 | 54 | const result = await rnn.generate({});
|
52 | 55 | expect(result.sample.length).toBe(20);
|
53 | 56 | });
|
54 | 57 |
|
55 |
| - it('generates content that follows the set options', async() => { |
| 58 | + it("generates content that follows the set options", async () => { |
56 | 59 | const result = await rnn.generate(RNN_OPTIONS);
|
57 | 60 | expect(result.sample.length).toBe(RNN_OPTIONS.length);
|
58 | 61 | });
|
|
0 commit comments