Skip to content

Commit cca6447

Browse files
authored
Change GMM test case (#990)
* Update regression test for GMR model to use random data and adjust expectation for probabilities * Improve some tests
1 parent 6533cec commit cca6447

File tree

4 files changed

+55
-53
lines changed

4 files changed

+55
-53
lines changed

tests/gui/view/diffusion_model.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ describe('generate', () => {
4848

4949
await expect(epoch.textContent()).resolves.toBe('10')
5050
await expect(methodFooter.textContent()).resolves.toMatch(/^loss/)
51-
})
51+
}, 60000)
5252
})

tests/gui/view/mds.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@ describe('dimensionality reduction', () => {
55
let page
66
beforeEach(async () => {
77
page = await getPage()
8+
const clusters = page.locator('#data_menu input[name=n]')
9+
await clusters.fill('1')
10+
const resetDataButton = page.locator('#data_menu input[value=Reset]')
11+
await resetDataButton.dispatchEvent('click')
12+
const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
13+
await taskSelectBox.selectOption('DR')
14+
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
15+
await modelSelectBox.selectOption('mds')
816
})
917

1018
afterEach(async () => {
1119
await page?.close()
1220
})
1321

1422
test('initialize', async () => {
15-
const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
16-
await taskSelectBox.selectOption('DR')
17-
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
18-
await modelSelectBox.selectOption('mds')
19-
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
20-
const buttons = await methodMenu.waitForSelector('.buttons')
23+
expect.assertions(0)
24+
const methodMenu = page.locator('#ml_selector #method_menu')
25+
const buttons = methodMenu.locator('.buttons')
2126

22-
const fitButton = await buttons.waitForSelector('input[value=Fit]')
23-
expect(fitButton).toBeDefined()
27+
const fitButton = buttons.locator('input[value=Fit]')
28+
await fitButton.waitFor()
2429
})
2530

2631
test('learn', async () => {
27-
const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
28-
await taskSelectBox.selectOption('DR')
29-
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
30-
await modelSelectBox.selectOption('mds')
31-
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
32-
const buttons = await methodMenu.waitForSelector('.buttons')
32+
const methodMenu = page.locator('#ml_selector #method_menu')
33+
const buttons = methodMenu.locator('.buttons')
3334

34-
const fitButton = await buttons.waitForSelector('input[value=Fit]')
35-
await fitButton.evaluate(el => el.click())
35+
const fitButton = buttons.locator('input[value=Fit]')
36+
await fitButton.dispatchEvent('click')
3637

37-
const svg = await page.waitForSelector('#plot-area svg')
38-
await svg.waitForSelector('.tile circle')
39-
const circles = await svg.$$('.tile circle')
40-
expect(circles).toHaveLength(300)
41-
}, 60000)
38+
const svg = page.locator('#plot-area svg')
39+
const circles = svg.locator('.tile circle')
40+
await expect(circles.count()).resolves.toBe(100)
41+
})
4242
})

tests/gui/view/word_to_vec.test.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ describe('word embedding', () => {
88
let page
99
beforeEach(async () => {
1010
page = await getPage()
11-
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
11+
const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
1212
await dataSelectBox.selectOption('text')
13-
const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
13+
const svg = page.locator('#plot-area svg')
14+
await svg.locator('.points circle').waitFor()
15+
const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
1416
await taskSelectBox.selectOption('WE')
15-
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
17+
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
1618
await modelSelectBox.selectOption('word_to_vec')
1719
})
1820

@@ -21,35 +23,35 @@ describe('word embedding', () => {
2123
})
2224

2325
test('initialize', async () => {
24-
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
25-
const buttons = await methodMenu.waitForSelector('.buttons')
26-
27-
const method = await buttons.waitForSelector('select:nth-of-type(1)')
28-
await expect((await method.getProperty('value')).jsonValue()).resolves.toBe('CBOW')
29-
const n = await buttons.waitForSelector('input:nth-of-type(1)')
30-
await expect(n.getAttribute('value')).resolves.toBe('1')
31-
const iteration = await buttons.waitForSelector('select:nth-of-type(2)')
32-
await expect((await iteration.getProperty('value')).jsonValue()).resolves.toBe('1')
33-
const rate = await buttons.waitForSelector('input:nth-of-type(3)')
34-
await expect(rate.getAttribute('value')).resolves.toBe('0.001')
35-
const batch = await buttons.waitForSelector('input:nth-of-type(4)')
36-
await expect(batch.getAttribute('value')).resolves.toBe('10')
26+
const methodMenu = page.locator('#ml_selector #method_menu')
27+
const buttons = methodMenu.locator('.buttons')
28+
29+
const method = buttons.locator('select').first()
30+
await expect(method.inputValue()).resolves.toBe('CBOW')
31+
const n = buttons.locator('input:nth-of-type(1)')
32+
await expect(n.inputValue()).resolves.toBe('1')
33+
const iteration = buttons.locator('select').nth(1)
34+
await expect(iteration.inputValue()).resolves.toBe('1')
35+
const rate = buttons.locator('input:nth-of-type(3)')
36+
await expect(rate.inputValue()).resolves.toBe('0.001')
37+
const batch = buttons.locator('input:nth-of-type(4)')
38+
await expect(batch.inputValue()).resolves.toBe('10')
3739
})
3840

3941
test('learn', async () => {
40-
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
41-
const buttons = await methodMenu.waitForSelector('.buttons')
42+
const methodMenu = page.locator('#ml_selector #method_menu')
43+
const buttons = methodMenu.locator('.buttons')
4244

43-
const epoch = await buttons.waitForSelector('[name=epoch]')
45+
const epoch = buttons.locator('[name=epoch]')
4446
await expect(epoch.textContent()).resolves.toBe('0')
45-
const methodFooter = await page.waitForSelector('#method_footer', { state: 'attached' })
47+
const methodFooter = page.locator('#method_footer', { state: 'attached' })
4648
await expect(methodFooter.textContent()).resolves.toBe('')
4749

48-
const initButton = await buttons.waitForSelector('input[value=Initialize]')
49-
await initButton.evaluate(el => el.click())
50-
const stepButton = await buttons.waitForSelector('input[value=Step]:enabled')
51-
await stepButton.evaluate(el => el.click())
52-
await buttons.waitForSelector('input[value=Step]:enabled')
50+
const initButton = buttons.locator('input[value=Initialize]')
51+
await initButton.dispatchEvent('click')
52+
const stepButton = buttons.locator('input[value=Step]:enabled')
53+
await stepButton.dispatchEvent('click')
54+
await buttons.locator('input[value=Step]:enabled').waitFor()
5355

5456
await expect(epoch.textContent()).resolves.toBe('1')
5557
await expect(methodFooter.textContent()).resolves.toMatch(/^loss/)

tests/lib/model/gmm.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ describe('regression', () => {
107107

108108
test('probability', () => {
109109
const model = new GMR()
110-
const x = [
111-
[0, 0],
112-
[1, 1],
113-
]
114-
const t = [[0], [1]]
110+
const x = Matrix.randn(50, 2, 0, 5).toArray()
111+
const t = []
112+
for (let i = 0; i < x.length; i++) {
113+
t[i] = [x[i][0] + x[i][1] + (Math.random() - 0.5) / 10]
114+
}
115115

116116
model.add()
117117
model.add()
@@ -127,7 +127,7 @@ describe('regression', () => {
127127
[[0], [-1]]
128128
)
129129
for (let c = 0; c < 2; c++) {
130-
expect(p[0][c]).toBeGreaterThan(p[1][c])
130+
expect(p[0][c]).toBeGreaterThanOrEqual(p[1][c])
131131
}
132132
})
133133
})

0 commit comments

Comments
 (0)