From 83ddc2cf6892a35527d3e8627840144cc7ca66df Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Thu, 26 Oct 2023 15:24:56 +0200 Subject: [PATCH] Tests for arrays --- tests/README.md | 14 +-- tests/array_append.json5 | 181 +++++++++++++++++++++++++++++++++++++ tests/array_concat.json5 | 105 +++++++++++++++++++++ tests/array_contains.json5 | 20 ++++ tests/array_element.json5 | 121 ++++++++++++++++++++++++- tests/array_find.json5 | 50 ++++++++++ tests/array_labels.json5 | 67 +++++++++++++- 7 files changed, 549 insertions(+), 9 deletions(-) diff --git a/tests/README.md b/tests/README.md index 5d166983..126a0b8d 100644 --- a/tests/README.md +++ b/tests/README.md @@ -23,16 +23,16 @@ This folder contains test cases for the openEO processes. - [x] arcsin - - [x] arctan - [x] arctan2 -- [ ] array_append +- [x] array_append - - [ ] array_apply -- [ ] array_concat -- [ ] array_contains -- [ ] array_create -- [ ] array_element +- [x] array_concat +- [x] array_contains +- [x] array_create +- [x] array_element - [ ] array_filter -- [ ] array_find +- [x] array_find - [ ] array_interpolate_linear -- [ ] array_labels +- [x] array_labels - [x] array_modify (experimental) - could use some more tests - [x] arsinh - [x] artanh - diff --git a/tests/array_append.json5 b/tests/array_append.json5 index c42b176f..9e72fd80 100644 --- a/tests/array_append.json5 +++ b/tests/array_append.json5 @@ -1,5 +1,28 @@ { "tests": [ + { + "arguments": { + "data": [], + "value": 0 + }, + "returns": [ + 1 + ] + }, + { + "arguments": { + "data": [ + 1, + 2 + ], + "value": null + }, + "returns": [ + 1, + 2, + null + ] + }, { "arguments": { "data": [ @@ -13,6 +36,164 @@ 2, 3 ] + }, + { + "arguments": { + "data": [ + true, + false + ], + "value": true + }, + "returns": [ + true, + false, + true + ] + }, + { + "arguments": { + "data": [ + true, + false + ], + "value": null + }, + "returns": [ + true, + false, + null + ] + }, + { + "arguments": { + "data": [ + "a", + "b" + ], + "value": "c" + }, + "returns": [ + "a", + "b" + "3" + ], + "optional": true + }, + { + "arguments": { + "data": [ + null, + 2 + ], + "value": "3" + }, + "returns": [ + null, + 2, + "3" + ], + // mixing data types is optional + "optional": true + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1.23 + }, + { + "key": "B02", + "value": 0.98 + } + ] + }, + "value": 4.56, + "label": "B03" + }, + "returns": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1.23 + }, + { + "key": "B02", + "value": 0.98 + }, + { + "key": "B03", + "value": 4.56 + } + ] + } + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": 2, + "value": 1.23 + }, + { + "key": 3, + "value": 0.98 + } + ] + }, + "value": 4.56, + "label": 5 + }, + "returns": { + "type": "labeled-array", + "data": [ + { + "key": 2, + "value": 1.23 + }, + { + "key": 3, + "value": 0.98 + }, + { + "key": 5, + "value": 4.56 + } + ] + } + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1.23 + } + ] + }, + "value": 4.56 + }, + "returns": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1.23 + }, + { + "key": 1, + "value": 4.56 + } + ] + } } ] } \ No newline at end of file diff --git a/tests/array_concat.json5 b/tests/array_concat.json5 index 11174ee0..b391e0e8 100644 --- a/tests/array_concat.json5 +++ b/tests/array_concat.json5 @@ -1,5 +1,29 @@ { "tests": [ + { + // Adds an empty array + "arguments": { + "array1": [ + 1 + ], + "array2": [] + }, + "returns": [ + 1 + ] + }, + { + // Adds to an empty array + "arguments": { + "array1": [], + "array2": [ + 1 + ] + }, + "returns": [ + 1 + ] + }, { // Concatenates two numerical arrays. "arguments": { @@ -34,7 +58,88 @@ "b", 1, 2 + ], + "optional": true + }, + { + // Check that a normal array and a labeled array lead to a normal array (labels get dropped) + "arguments": { + "array1": [ + 1, + 2 + ], + "array2": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 3 + }, + { + "key": "B02", + "value": 4 + } + ] + } + }, + "returns": [ + 1, + 2, + 3, + 4 ] + }, + { + // Check that a labeled arrays are supported + "arguments": { + "array1": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1 + }, + { + "key": "B02", + "value": 2 + } + ] + }, + "array2": { + "type": "labeled-array", + "data": [ + { + "key": "B03", + "value": 3 + }, + { + "key": "B04", + "value": 4 + } + ] + } + }, + "returns": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 1 + }, + { + "key": "B02", + "value": 2 + }, + { + "key": "B03", + "value": 3 + }, + { + "key": "B04", + "value": 4 + } + ] + } } ] } \ No newline at end of file diff --git a/tests/array_contains.json5 b/tests/array_contains.json5 index 402977a2..38da6f3d 100644 --- a/tests/array_contains.json5 +++ b/tests/array_contains.json5 @@ -22,6 +22,26 @@ }, "returns": false }, + { + "arguments": { + "data": [ + false, + false + ], + "value": false + }, + "returns": true + }, + { + "arguments": { + "data": [ + true, + true + ], + "value": false + }, + "returns": false + }, { "arguments": { "data": [ diff --git a/tests/array_element.json5 b/tests/array_element.json5 index 4d543ef6..f9f58cfd 100644 --- a/tests/array_element.json5 +++ b/tests/array_element.json5 @@ -31,6 +31,125 @@ "return_nodata": true }, "returns": null - } + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 4 + }, + { + "key": "B02", + "value": 5 + }, + { + "key": "B03", + "value": 6 + } + ] + }, + "label": "BO2" + }, + "returns": 5 + }, + { + "arguments": { + "data": [ + 1 + ] + }, + "throws": "ArrayElementParameterMissing" + }, + { + "arguments": { + "data": [ + 1 + ], + "index": 0, + "label": 0 + }, + "throws": "ArrayElementParameterConflict" + }, + { + "arguments": { + "data": [ + 1, + 2 + ], + "index": 2 + }, + "throws": "ArrayElementNotAvailable" + }, + { + "arguments": { + "data": [ + 1, + 2 + ], + "index": -1 + }, + "throws": "ArrayElementNotAvailable" + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 4 + }, + { + "key": "B02", + "value": 5 + }, + { + "key": "B03", + "value": 6 + } + ] + }, + "label": "BO4" + }, + "throws": "ArrayElementNotAvailable" + }, + { + "arguments": { + "data": [ + 1, + 2 + ], + "index": 2, + "return_nodata": true + }, + "returns": null + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 4 + }, + { + "key": "B02", + "value": 5 + }, + { + "key": "B03", + "value": 6 + } + ] + }, + "label": "BO4", + "return_nodata": true + }, + "returns": null + }, ] } \ No newline at end of file diff --git a/tests/array_find.json5 b/tests/array_find.json5 index aad20aa6..9c5b5f69 100644 --- a/tests/array_find.json5 +++ b/tests/array_find.json5 @@ -38,6 +38,56 @@ }, "returns": null }, + { + "arguments": { + "data": [ + false, + false + ], + "value": false + }, + "returns": 0 + }, + { + "arguments": { + "data": [ + false, + false + ], + "value": false, + "reverse": true + }, + "returns": 1 + }, + { + "arguments": { + "data": [ + true, + true + ], + "value": false + }, + "returns": null + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B03", + "value": 3 + }, + { + "key": "B04", + "value": 4 + } + ] + }, + "value": 3 + }, + "returns": 1 + }, { "arguments": { "data": [ diff --git a/tests/array_labels.json5 b/tests/array_labels.json5 index 308e1aa1..e01416a4 100644 --- a/tests/array_labels.json5 +++ b/tests/array_labels.json5 @@ -1,3 +1,68 @@ { - "tests": [] + "tests": [ + { + "arguments": { + "data": [] + }, + "returns": [] + }, + { + "arguments": { + "data": [ + 1, + 2, + 3, + null + ] + }, + "returns": [ + 0, + 1, + 2, + 3 + ] + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": "B01", + "value": 3 + }, + { + "key": "B02", + "value": 4 + } + ] + } + }, + "returns": [ + "B01", + "B02" + ] + }, + { + "arguments": { + "data": { + "type": "labeled-array", + "data": [ + { + "key": 1, + "value": 3 + }, + { + "key": 2, + "value": 4 + } + ] + } + }, + "returns": [ + 1, + 2 + ] + } + ] } \ No newline at end of file