(mode)
| 5 | describe('Math.random() unique'); |
| 6 | |
| 7 | function mathRandomUnique(mode) { |
| 8 | const gpu = new GPU({ mode }); |
| 9 | const checkCount = 20; |
| 10 | let seed1 = Math.random(); |
| 11 | let seed2 = Math.random(); |
| 12 | let stub = sinon.stub(mathRandom, 'onBeforeRun').callsFake((kernel) => { |
| 13 | kernel.setUniform1f('randomSeed1', seed1); |
| 14 | kernel.setUniform1f('randomSeed2', seed2); |
| 15 | }); |
| 16 | try { |
| 17 | gpu.addNativeFunction('getSeed', `highp float getSeed() { |
| 18 | return randomSeedShift; |
| 19 | }`); |
| 20 | const kernel = gpu.createKernel(function () { |
| 21 | const v = Math.random(); |
| 22 | return getSeed(); |
| 23 | }, {output: [1]}); |
| 24 | const results = []; |
| 25 | for (let i = 0; i < checkCount; i++) { |
| 26 | const result = kernel(); |
| 27 | assert.ok(results.indexOf(result[0]) === -1, `duplication at index ${results.indexOf(result[0])} from new value ${result[0]}. Values ${JSON.stringify(results)}`); |
| 28 | results.push(result[0]); |
| 29 | seed2 = result[0]; |
| 30 | assert.ok(stub.called); |
| 31 | stub.restore(); |
| 32 | stub.callsFake((kernel) => { |
| 33 | kernel.setUniform1f('randomSeed1', seed1); |
| 34 | kernel.setUniform1f('randomSeed2', seed2); |
| 35 | }); |
| 36 | } |
| 37 | } finally { |
| 38 | stub.restore(); |
| 39 | gpu.destroy(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | test('unique every time auto', () => { |
| 44 | mathRandomUnique(); |
no test coverage detected
searching dependent graphs…