From 60622de55112463b47f540893f8d5e5e5d69f521 Mon Sep 17 00:00:00 2001 From: RickBarretto <78623871+RickBarretto@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:03:21 -0300 Subject: [PATCH 1/2] [Collections\array] add unitt tests --- tests/unitt/lib/collections/array.test.art | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/unitt/lib/collections/array.test.art diff --git a/tests/unitt/lib/collections/array.test.art b/tests/unitt/lib/collections/array.test.art new file mode 100644 index 0000000000..db8482deb1 --- /dev/null +++ b/tests/unitt/lib/collections/array.test.art @@ -0,0 +1,103 @@ +import {unitt}! +import relative {../../commons/functions}! + +suite "array.of: :integer" [ + + test "array.of: n returns a n-size :block" [ + expected: ['done 'done 'done] + actual: array.of: 3 'done + assert -> equal? expected actual + ] + + test "array.of: n returns a n-size :block even when the source is a :block" [ + expected: [['done] ['done] ['done]] + actual: array.of: 3 ['done] + assert -> equal? expected actual + ] +] + + +suite "array.of: :block - n-dimensional arrays" [ + + test "array.of: [3 4] returns a 3x4 matrix :block" [ + expected: [ + [0 0 0 0] + [0 0 0 0] + [0 0 0 0] + ] + + actual: array.of: [3, 4] 0 + assert -> equal? expected actual + ] + + test "array.of: [3 4] returns a 3x4 matrix :block preserving the :block source" [ + expected: [ + [[0] [0] [0] [0]] + [[0] [0] [0] [0]] + [[0] [0] [0] [0]] + ] + + actual: array.of: [3, 4] [0] + assert -> equal? expected actual + ] + + test "array.of: [3 3 3] return a 3-dimensional array" [ + expected: [ + [ + [:point :point :point] + [:point :point :point] + [:point :point :point] + ] + [ + [:point :point :point] + [:point :point :point] + [:point :point :point] + ] + [ + [:point :point :point] + [:point :point :point] + [:point :point :point] + ] + ] + + actual: array.of: [3, 3, 3] :point + assert -> equal? expected actual + ] +] + +suite "array " [ + + test "array :range should return a :block from iteration" [ + assert -> equal? [1 2 3] @1..3 + assert -> equal? [1 2 3] @1..3.2 + assert -> equal? ['a' 'b' 'c'] @'a'..'c' + ] + + test "array :range should respect .step" [ + assert -> equal? [1 3 5] @range.step: 2 1 5 + assert -> equal? ['a' 'c'] @range.step: 2 'a' 'c' + ] + + test "array :block should evaluate it" [ + data: [ + append "Art" "uro" + join.with: " " ["is" "awesome!"] + ] + + expected: ["Arturo" "is awesome!"] + actual: @data + + assert -> notEqual? expected data + assert -> equal? expected actual + ] + + test "array :any should wrap and evaluate it into a :block" [ + data: [pi] + expected: [3.141592653589793] + actual: @data + + assert -> notEqual? expected data + assert -> equal? expected actual + ] + +] \ No newline at end of file From 51f93a45d103076b86ad68b05bb7e20ee37ca81c Mon Sep 17 00:00:00 2001 From: RickBarretto <78623871+RickBarretto@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:05:18 -0300 Subject: [PATCH 2/2] [Collections\array] add TODO --- tests/unitt/lib/collections/array.test.art | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unitt/lib/collections/array.test.art b/tests/unitt/lib/collections/array.test.art index db8482deb1..d09885eeed 100644 --- a/tests/unitt/lib/collections/array.test.art +++ b/tests/unitt/lib/collections/array.test.art @@ -100,4 +100,6 @@ suite "array " [ assert -> equal? expected actual ] -] \ No newline at end of file +] + +; todo(Collections\array) add file reading tests from #1786 \ No newline at end of file