1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/* Unit Test: New Table Operations (t.shape, t.append, t.prepend) */
..out "=== Testing New Table Operations ===";
/* ===== t.shape TESTS ===== */
/* Test t.shape on array-like table */
arr : {1, 2, 3, 4, 5};
arr_shape : t.shape arr;
..assert arr_shape.size = 5;
..assert arr_shape.type = "array";
/* Test t.shape on object-like table */
obj : {name: "Alice", age: 30, city: "NYC"};
obj_shape : t.shape obj;
..assert obj_shape.size = 3;
..assert obj_shape.type = "object";
/* Test t.shape on mixed table (non-sequential keys) */
mixed : {1: "one", 3: "three", name: "test"};
mixed_shape : t.shape mixed;
..assert mixed_shape.size = 3;
..assert mixed_shape.type = "object";
/* Test t.shape on empty table */
empty : {};
empty_shape : t.shape empty;
..assert empty_shape.size = 0;
..assert empty_shape.type = "array";
/* ===== t.append TESTS ===== */
/* Test t.append on array-like table */
numbers : {1, 2, 3};
appended : t.append numbers 4;
..assert appended[1] = 1;
..assert appended[2] = 2;
..assert appended[3] = 3;
..assert appended[4] = 4;
/* Verify original unchanged (immutability) */
..assert numbers[1] = 1;
..assert numbers[2] = 2;
..assert numbers[3] = 3;
/* Test t.append on empty table */
empty_arr : {};
first_item : t.append empty_arr "hello";
..assert first_item[1] = "hello";
/* Test t.append with different data types */
multi_type : {1, "two"};
with_bool : t.append multi_type true;
..assert with_bool[1] = 1;
..assert with_bool[2] = "two";
..assert with_bool[3] = true;
/* ===== t.prepend TESTS ===== */
/* Test t.prepend on array-like table */
original : {10, 20, 30};
prepended : t.prepend original 5;
..assert prepended[1] = 5;
..assert prepended[2] = 10;
..assert prepended[3] = 20;
..assert prepended[4] = 30;
/* Verify original unchanged (immutability) */
..assert original[1] = 10;
..assert original[2] = 20;
..assert original[3] = 30;
/* Test t.prepend on empty table */
empty_prep : {};
first_prep : t.prepend empty_prep "start";
..assert first_prep[1] = "start";
/* Test t.prepend with object keys preserved */
obj_with_nums : {1: "one", 2: "two", name: "test"};
obj_prepended : t.prepend obj_with_nums "zero";
..assert obj_prepended[1] = "zero";
..assert obj_prepended[2] = "one";
..assert obj_prepended[3] = "two";
..assert obj_prepended.name = "test";
/* ===== COMBINED OPERATIONS TESTS ===== */
/* Test chaining operations */
base : {10, 20};
step1 : t.append base 30;
step2 : t.prepend step1 5;
final_shape : t.shape step2;
..assert step2[1] = 5;
..assert step2[2] = 10;
..assert step2[3] = 20;
..assert step2[4] = 30;
..assert final_shape.size = 4;
..assert final_shape.type = "array";
/* Test with functional combinators */
data : {1, 2, 3};
doubled : map x -> x * 2 data;
extended : t.append doubled 8;
final_doubled : t.prepend extended 0;
..assert final_doubled[1] = 0;
..assert final_doubled[2] = 2;
..assert final_doubled[3] = 4;
..assert final_doubled[4] = 6;
..assert final_doubled[5] = 8;
/* ===== ERROR HANDLING TESTS ===== */
/* These should handle gracefully or show appropriate errors */
/* Note: Specific error behavior depends on implementation */
..out "=== New Table Operations Tests Complete ===";
|