summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webnn/validation_tests/pad.https.any.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/webnn/validation_tests/pad.https.any.js')
-rw-r--r--testing/web-platform/tests/webnn/validation_tests/pad.https.any.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webnn/validation_tests/pad.https.any.js b/testing/web-platform/tests/webnn/validation_tests/pad.https.any.js
index 11c6a8f7ef..cc39bee4c0 100644
--- a/testing/web-platform/tests/webnn/validation_tests/pad.https.any.js
+++ b/testing/web-platform/tests/webnn/validation_tests/pad.https.any.js
@@ -15,3 +15,73 @@ multi_builder_test(async (t, builder, otherBuilder) => {
() =>
builder.pad(inputFromOtherBuilder, beginningPadding, endingPadding));
}, '[pad] throw if input is from another builder');
+
+const tests = [
+ {
+ name:
+ '[pad] Test with default options, beginningPadding=[1, 2] and endingPadding=[1, 2].',
+ input: {dataType: 'float32', dimensions: [2, 3]},
+ beginningPadding: [1, 2],
+ endingPadding: [1, 2],
+ options: {
+ mode: 'constant',
+ value: 0,
+ },
+ output: {dataType: 'float32', dimensions: [4, 7]}
+ },
+ {
+ name: '[pad] Throw if building pad for scalar input.',
+ input: {dataType: 'float32', dimensions: []},
+ beginningPadding: [],
+ endingPadding: [],
+ },
+ {
+ name:
+ '[pad] Throw if the length of beginningPadding is not equal to the input rank.',
+ input: {dataType: 'float32', dimensions: [2, 3]},
+ beginningPadding: [1],
+ endingPadding: [1, 2],
+ options: {
+ mode: 'edge',
+ value: 0,
+ },
+ },
+ {
+ name:
+ '[pad] Throw if the length of endingPadding is not equal to the input rank.',
+ input: {dataType: 'float32', dimensions: [2, 3]},
+ beginningPadding: [1, 0],
+ endingPadding: [1, 2, 0],
+ options: {
+ mode: 'reflection',
+ },
+ },
+ {
+ name: '[pad] Throw if the padding of one dimension is too large.',
+ input: {dataType: 'float32', dimensions: [2, 3]},
+ beginningPadding: [2294967295, 0],
+ endingPadding: [3294967295, 2],
+ options: {
+ mode: 'reflection',
+ },
+ },
+];
+
+tests.forEach(
+ test => promise_test(async t => {
+ const input = builder.input(
+ 'input',
+ {dataType: test.input.dataType, dimensions: test.input.dimensions});
+ if (test.output) {
+ const output = builder.pad(
+ input, test.beginningPadding, test.endingPadding, test.options);
+ assert_equals(output.dataType(), test.output.dataType);
+ assert_array_equals(output.shape(), test.output.dimensions);
+ } else {
+ assert_throws_js(
+ TypeError,
+ () => builder.pad(
+ input, test.beginningPadding, test.endingPadding,
+ test.options));
+ }
+ }, test.name));