about summary refs log tree commit diff stats
path: root/js/scripting-lang/scratch_tests/test_each_combinator.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/scratch_tests/test_each_combinator.txt')
-rw-r--r--js/scripting-lang/scratch_tests/test_each_combinator.txt59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/scripting-lang/scratch_tests/test_each_combinator.txt b/js/scripting-lang/scratch_tests/test_each_combinator.txt
new file mode 100644
index 0000000..487b0f0
--- /dev/null
+++ b/js/scripting-lang/scratch_tests/test_each_combinator.txt
@@ -0,0 +1,59 @@
+/* Test each combinator for APL-style element-wise operations */
+
+/* Basic table creation */
+numbers : {1, 2, 3, 4, 5};
+table1 : {a: 1, b: 2, c: 3};
+table2 : {a: 10, b: 20, c: 30};
+
+/* Test each with no tables (backward compatibility) */
+normal_add : each @add 5 3;
+/* Expected: 8 */
+
+/* Test each with single table */
+double : x -> x * 2;
+each_result : each @double numbers;
+/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */
+
+/* Test each with mixed table and scalar */
+mixed_operation : each @add numbers 10;
+/* Expected: {1: 11, 2: 12, 3: 13, 4: 14, 5: 15} */
+
+/* Test each with multiple tables */
+multi_table_sum : each @add table1 table2;
+/* Expected: {a: 11, b: 22, c: 33} */
+
+/* Test each with three arguments using composition */
+add_100 : x -> add x 100;
+triple_sum : each @add_100 table1;
+/* Expected: {a: 101, b: 102, c: 103} */
+
+/* Test nested table operations */
+nested : {
+    data: {a: 1, b: 2, c: 3},
+    meta: {type: "numbers", count: 3}
+};
+
+/* Top-level only (nested tables unchanged) */
+top_level_only : each @double nested;
+/* Expected: {data: {a: 1, b: 2, c: 3}, meta: {type: "numbers", count: 3}} */
+
+/* Nested operations with explicit composition */
+nested_doubled : each (each @double) nested;
+/* Expected: {data: {a: 2, b: 4, c: 6}, meta: {type: "numbers", count: 3}} */
+
+/* Output results */
+..out "=== EACH COMBINATOR TESTS ===";
+..out "Normal add (no tables):";
+..out normal_add;
+..out "Each with single table:";
+..out each_result;
+..out "Each with mixed table and scalar:";
+..out mixed_operation;
+..out "Each with multiple tables:";
+..out multi_table_sum;
+..out "Each with three arguments using composition:";
+..out triple_sum;
+..out "Top-level only (nested):";
+..out top_level_only;
+..out "Nested with explicit composition:";
+..out nested_doubled; 
\ No newline at end of file