Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imrove test coverage for Grid layers and utils
- Loading branch information
Showing
9 changed files
with
256 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
test/modules/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2015 - 2019 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import test from 'tape-catch'; | ||
import {Buffer} from '@luma.gl/core'; | ||
import {testLayer, testInitializeLayer} from '@deck.gl/test-utils'; | ||
import GPUGridCellLayer from '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer'; | ||
import {setupSpysForWebGL1, restoreSpies} from './webgl1-spies-utils'; | ||
import {gl} from '@deck.gl/test-utils'; | ||
const SAMPLE_BUFFER = new Buffer(gl); | ||
const SAMPLE_PROPS = { | ||
data: { | ||
color: { | ||
aggregationBuffer: SAMPLE_BUFFER, | ||
maxMinBuffer: SAMPLE_BUFFER | ||
}, | ||
elevation: { | ||
aggregationBuffer: SAMPLE_BUFFER, | ||
maxMinBuffer: SAMPLE_BUFFER | ||
} | ||
} | ||
}; | ||
|
||
test('GPUGridCellLayer#initializeState', t => { | ||
const webgl1Spies = setupSpysForWebGL1(gl); | ||
const layer = new GPUGridCellLayer(SAMPLE_PROPS); | ||
|
||
testInitializeLayer({layer, onError: t.notOk}); | ||
|
||
t.ok(layer.state.model, 'should set state.model'); | ||
|
||
restoreSpies(webgl1Spies); | ||
t.end(); | ||
}); | ||
|
||
test('GPUGridCellLayer#updates', t => { | ||
const webgl1Spies = setupSpysForWebGL1(gl); | ||
|
||
testLayer({ | ||
Layer: GPUGridCellLayer, | ||
onError: t.notOk, | ||
testCases: [ | ||
{ | ||
props: SAMPLE_PROPS, | ||
onAfterUpdate({layer}) { | ||
t.ok(layer.state.model, 'should set state.model'); | ||
} | ||
}, | ||
{ | ||
updateProps: { | ||
cellSize: 123 | ||
}, | ||
onAfterUpdate({layer, spies}) { | ||
t.ok( | ||
layer.state.model.program.uniforms.cellSize === 123, | ||
'cellSize unifrom should get updated' | ||
); | ||
} | ||
} | ||
] | ||
}); | ||
|
||
restoreSpies(webgl1Spies); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
test/modules/aggregation-layers/gpu-grid-layer/webgl1-spies-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2015 - 2019 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import {isWebGL2} from '@luma.gl/core'; | ||
import {_GPUGridAggregator as GPUGridAggregator} from '@deck.gl/aggregation-layers'; | ||
import GPUGridCellLayer from '@deck.gl/aggregation-layers/gpu-grid-layer/gpu-grid-cell-layer'; | ||
import {makeSpy} from '@probe.gl/test-utils'; | ||
|
||
const VS = 'void main() {gl_Position = vec4(0);}'; | ||
const FS = 'void main() {gl_FragColor = vec4(0);}'; | ||
|
||
// Spiy methods to avoid usage of WebGL2 API when running under Node. | ||
export function setupSpysForWebGL1(gl) { | ||
let getShadersSpy = null; | ||
let setupUniformBufferSpy = null; | ||
let bindUniformBuffersSpy = null; | ||
let unbindUniformBuffersSpy = null; | ||
let isSupportedSpy = null; | ||
if (!isWebGL2(gl)) { | ||
isSupportedSpy = makeSpy(GPUGridAggregator, 'isSupported'); | ||
getShadersSpy = makeSpy(GPUGridCellLayer.prototype, 'getShaders'); | ||
setupUniformBufferSpy = makeSpy(GPUGridCellLayer.prototype, '_setupUniformBuffer'); | ||
bindUniformBuffersSpy = makeSpy(GPUGridCellLayer.prototype, 'bindUniformBuffers'); | ||
unbindUniformBuffersSpy = makeSpy(GPUGridCellLayer.prototype, 'unbindUniformBuffers'); | ||
getShadersSpy.returns({ | ||
vs: VS, | ||
fs: FS, | ||
modules: ['project32', 'gouraud-lighting', 'picking', 'fp64'] | ||
}); | ||
isSupportedSpy.returns(true); | ||
setupUniformBufferSpy.returns(null); | ||
bindUniformBuffersSpy.returns(null); | ||
unbindUniformBuffersSpy.returns(null); | ||
} | ||
return { | ||
getShadersSpy, | ||
setupUniformBufferSpy, | ||
bindUniformBuffersSpy, | ||
unbindUniformBuffersSpy, | ||
isSupportedSpy | ||
}; | ||
} | ||
|
||
export function restoreSpies(spies) { | ||
for (const name in spies) { | ||
if (spies[name]) { | ||
spies[name].restore(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/modules/aggregation-layers/utils/aggregation-operation-utils.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2015 - 2019 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import test from 'tape-catch'; | ||
|
||
import {getValueFunc} from '@deck.gl/aggregation-layers/utils/aggregation-operation-utils'; | ||
|
||
const data = [10, 'a', null, 14, -3, 16, 0.2]; | ||
const accessor = x => x; | ||
const TEST_CASES = [ | ||
{ | ||
name: 'Min Function', | ||
op: 'min', | ||
data, | ||
expected: -3 | ||
}, | ||
{ | ||
name: 'Max Function', | ||
op: 'Max', | ||
data, | ||
expected: 16 | ||
}, | ||
{ | ||
name: 'Sum Function', | ||
op: 'sUM', | ||
data, | ||
expected: 37.2 | ||
}, | ||
{ | ||
name: 'Mean Function', | ||
op: 'MEAN', | ||
data, | ||
expected: 37.2 / 5 | ||
}, | ||
{ | ||
name: 'Invalid(should default to SUM)', | ||
op: 'Invalid', | ||
data, | ||
expected: 37.2 | ||
} | ||
]; | ||
|
||
test('GridAggregationOperationUtils#getValueFunc', t => { | ||
TEST_CASES.forEach(tc => { | ||
const func = getValueFunc(tc.op, accessor); | ||
t.ok(func(data) === tc.expected, `${tc.name} should return expected result`); | ||
}); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters