about summary refs log tree commit diff stats
path: root/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/scratch_tests/test_table_enhancements_working.txt')
-rw-r--r--js/scripting-lang/scratch_tests/test_table_enhancements_working.txt102
1 files changed, 102 insertions, 0 deletions
diff --git a/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt b/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt
new file mode 100644
index 0000000..e73a6df
--- /dev/null
+++ b/js/scripting-lang/scratch_tests/test_table_enhancements_working.txt
@@ -0,0 +1,102 @@
+/* Test working table enhancements */
+
+/* Basic table creation */
+numbers : {1, 2, 3, 4, 5};
+person : {name: "Alice", age: 30, active: true};
+table1 : {a: 1, b: 2, c: 3};
+table2 : {a: 10, b: 20, c: 30};
+
+/* Test enhanced map (working) */
+double : x -> x * 2;
+doubled : map @double numbers;
+/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */
+
+/* Test enhanced filter (working) */
+isEven : x -> x % 2 == 0;
+even_numbers : filter @isEven numbers;
+/* Expected: {2: 2, 4: 4} */
+
+/* Test enhanced reduce (working) */
+sum : x y -> x + y;
+total : reduce @sum 0 numbers;
+/* Expected: 15 */
+
+/* Test t.map (working) */
+t_doubled : t.map @double numbers;
+/* Expected: {1: 2, 2: 4, 3: 6, 4: 8, 5: 10} */
+
+/* Test t.filter (working) */
+t_even_numbers : t.filter @isEven numbers;
+/* Expected: {2: 2, 4: 4} */
+
+/* Test t.reduce (working) */
+t_total : t.reduce @sum 0 numbers;
+/* Expected: 15 */
+
+/* Test t.set (working) */
+updated_person : t.set person "age" 31;
+/* Expected: {name: "Alice", age: 31, active: true} */
+
+/* Test t.delete (working) */
+without_age : t.delete person "age";
+/* Expected: {name: "Alice", active: true} */
+
+/* Test t.merge (working) */
+merged : t.merge person {city: "New York", country: "USA"};
+/* Expected: {name: "Alice", age: 30, active: true, city: "New York", country: "USA"} */
+
+/* Test t.pairs, t.keys, t.values, t.length (working) */
+all_pairs : t.pairs person;
+all_keys : t.keys person;
+all_values : t.values person;
+table_size : t.length person;
+
+/* Test t.has and t.get (working) */
+has_name : t.has person "name";
+has_email : t.has person "email";
+age_or_default : t.get person "age" 0;
+email_or_default : t.get person "email" "unknown";
+
+/* Test function composition with tables (working) */
+transform : compose @t.map @double @t.filter @isEven;
+transformed : transform numbers;
+/* Expected: {2: 4, 4: 8} */
+
+/* Output results */
+..out "=== WORKING TABLE ENHANCEMENTS ===";
+..out "Enhanced map:";
+..out doubled;
+..out "Enhanced filter:";
+..out even_numbers;
+..out "Enhanced reduce:";
+..out total;
+..out "t.map:";
+..out t_doubled;
+..out "t.filter:";
+..out t_even_numbers;
+..out "t.reduce:";
+..out t_total;
+..out "t.set:";
+..out updated_person;
+..out "t.delete:";
+..out without_age;
+..out "t.merge:";
+..out merged;
+..out "t.pairs:";
+..out all_pairs;
+..out "t.keys:";
+..out all_keys;
+..out "t.values:";
+..out all_values;
+..out "t.length:";
+..out table_size;
+..out "t.has name:";
+..out has_name;
+..out "t.has email:";
+..out has_email;
+..out "t.get age:";
+..out age_or_default;
+..out "t.get email:";
+..out email_or_default;
+..out "Function composition:";
+..out transformed; 
\ No newline at end of file