yukigo 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +26 -0
- package/README.md +193 -199
- package/dist/analyzer/GraphBuilder.d.ts +29 -0
- package/dist/analyzer/GraphBuilder.js +99 -0
- package/dist/analyzer/index.d.ts +11 -23
- package/dist/analyzer/index.js +100 -58
- package/dist/analyzer/inspections/functional/functional.d.ts +44 -0
- package/dist/analyzer/inspections/functional/functional.js +149 -0
- package/dist/analyzer/inspections/functional/smells.d.ts +16 -0
- package/dist/analyzer/inspections/functional/smells.js +98 -0
- package/dist/analyzer/inspections/{generic.d.ts → generic/generic.d.ts} +70 -43
- package/dist/analyzer/inspections/generic/generic.js +604 -0
- package/dist/analyzer/inspections/generic/smells.d.ts +61 -0
- package/dist/analyzer/inspections/generic/smells.js +349 -0
- package/dist/analyzer/inspections/imperative/imperative.d.ts +35 -0
- package/dist/analyzer/inspections/imperative/imperative.js +109 -0
- package/dist/analyzer/inspections/imperative/smells.d.ts +16 -0
- package/dist/analyzer/inspections/imperative/smells.js +58 -0
- package/dist/analyzer/inspections/logic/logic.d.ts +32 -0
- package/dist/analyzer/inspections/logic/logic.js +96 -0
- package/dist/analyzer/inspections/logic/smells.d.ts +15 -0
- package/dist/analyzer/inspections/logic/smells.js +60 -0
- package/dist/analyzer/inspections/object/object.d.ts +88 -0
- package/dist/analyzer/inspections/object/object.js +319 -0
- package/dist/analyzer/inspections/object/smells.d.ts +30 -0
- package/dist/analyzer/inspections/object/smells.js +135 -0
- package/dist/analyzer/utils.d.ts +26 -4
- package/dist/analyzer/utils.js +71 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpreter/components/EnvBuilder.d.ts +9 -5
- package/dist/interpreter/components/EnvBuilder.js +100 -30
- package/dist/interpreter/components/Operations.d.ts +4 -4
- package/dist/interpreter/components/Operations.js +17 -2
- package/dist/interpreter/components/PatternMatcher.d.ts +47 -17
- package/dist/interpreter/components/PatternMatcher.js +264 -119
- package/dist/interpreter/components/RuntimeContext.d.ts +35 -0
- package/dist/interpreter/components/RuntimeContext.js +93 -0
- package/dist/interpreter/components/TestRunner.d.ts +18 -0
- package/dist/interpreter/components/TestRunner.js +103 -0
- package/dist/interpreter/components/Visitor.d.ts +63 -57
- package/dist/interpreter/components/Visitor.js +508 -173
- package/dist/interpreter/components/logic/LogicEngine.d.ts +29 -0
- package/dist/interpreter/components/logic/LogicEngine.js +259 -0
- package/dist/interpreter/components/logic/LogicResolver.d.ts +53 -0
- package/dist/interpreter/components/logic/LogicResolver.js +471 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +14 -0
- package/dist/interpreter/components/logic/LogicTranslator.js +99 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +12 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +147 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +19 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.js +269 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +126 -0
- package/dist/interpreter/entities.d.ts +105 -0
- package/dist/interpreter/entities.js +96 -0
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/index.d.ts +4 -12
- package/dist/interpreter/index.js +10 -13
- package/dist/interpreter/trampoline.d.ts +17 -0
- package/dist/interpreter/trampoline.js +38 -0
- package/dist/interpreter/utils.d.ts +4 -7
- package/dist/interpreter/utils.js +25 -17
- package/dist/tester/index.d.ts +25 -0
- package/dist/tester/index.js +108 -0
- package/dist/utils/helpers.d.ts +0 -4
- package/dist/utils/helpers.js +20 -24
- package/package.json +2 -2
- package/src/analyzer/GraphBuilder.ts +142 -0
- package/src/analyzer/index.ts +185 -132
- package/src/analyzer/inspections/functional/functional.ts +121 -0
- package/src/analyzer/inspections/functional/smells.ts +102 -0
- package/src/analyzer/inspections/{generic.ts → generic/generic.ts} +581 -499
- package/src/analyzer/inspections/generic/smells.ts +365 -0
- package/src/analyzer/inspections/imperative/imperative.ts +101 -0
- package/src/analyzer/inspections/imperative/smells.ts +54 -0
- package/src/analyzer/inspections/logic/logic.ts +90 -0
- package/src/analyzer/inspections/logic/smells.ts +54 -0
- package/src/analyzer/inspections/{object.ts → object/object.ts} +264 -282
- package/src/analyzer/inspections/object/smells.ts +144 -0
- package/src/analyzer/utils.ts +109 -26
- package/src/index.ts +3 -2
- package/src/interpreter/components/EnvBuilder.ts +202 -97
- package/src/interpreter/components/Operations.ts +99 -81
- package/src/interpreter/components/PatternMatcher.ts +475 -254
- package/src/interpreter/components/RuntimeContext.ts +119 -0
- package/src/interpreter/components/TestRunner.ts +151 -0
- package/src/interpreter/components/Visitor.ts +1065 -493
- package/src/interpreter/components/logic/LogicEngine.ts +519 -0
- package/src/interpreter/components/logic/LogicResolver.ts +858 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +149 -0
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +227 -0
- package/src/interpreter/components/runtimes/LazyRuntime.ts +334 -0
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +224 -0
- package/src/interpreter/errors.ts +47 -47
- package/src/interpreter/index.ts +52 -59
- package/src/interpreter/trampoline.ts +71 -0
- package/src/interpreter/utils.ts +84 -79
- package/src/tester/index.ts +128 -0
- package/src/utils/helpers.ts +67 -73
- package/tests/analyzer/functional.spec.ts +207 -221
- package/tests/analyzer/generic.spec.ts +178 -100
- package/tests/analyzer/helpers.spec.ts +83 -83
- package/tests/analyzer/logic.spec.ts +237 -292
- package/tests/analyzer/oop.spec.ts +323 -338
- package/tests/analyzer/transitive.spec.ts +166 -0
- package/tests/interpreter/EnvBuilder.spec.ts +183 -178
- package/tests/interpreter/FunctionRuntime.spec.ts +223 -234
- package/tests/interpreter/LazyRuntime.spec.ts +225 -190
- package/tests/interpreter/LogicEngine.spec.ts +327 -194
- package/tests/interpreter/LogicSubstitution.spec.ts +80 -0
- package/tests/interpreter/ObjectRuntime.spec.ts +606 -0
- package/tests/interpreter/Operations.spec.ts +220 -220
- package/tests/interpreter/PatternSystem.spec.ts +213 -189
- package/tests/interpreter/Tests.spec.ts +122 -0
- package/tests/interpreter/interpreter.spec.ts +991 -937
- package/tests/tester/Tester.spec.ts +153 -0
- package/tsconfig.build.json +15 -7
- package/tsconfig.json +25 -17
- package/dist/analyzer/inspections/functional.d.ts +0 -46
- package/dist/analyzer/inspections/functional.js +0 -123
- package/dist/analyzer/inspections/generic.js +0 -427
- package/dist/analyzer/inspections/imperative.d.ts +0 -37
- package/dist/analyzer/inspections/imperative.js +0 -105
- package/dist/analyzer/inspections/logic.d.ts +0 -49
- package/dist/analyzer/inspections/logic.js +0 -140
- package/dist/analyzer/inspections/object.d.ts +0 -83
- package/dist/analyzer/inspections/object.js +0 -235
- package/dist/interpreter/components/FunctionRuntime.d.ts +0 -8
- package/dist/interpreter/components/FunctionRuntime.js +0 -52
- package/dist/interpreter/components/LazyRuntime.d.ts +0 -7
- package/dist/interpreter/components/LazyRuntime.js +0 -75
- package/dist/interpreter/components/LogicEngine.d.ts +0 -21
- package/dist/interpreter/components/LogicEngine.js +0 -152
- package/dist/interpreter/components/LogicResolver.d.ts +0 -11
- package/dist/interpreter/components/LogicResolver.js +0 -87
- package/src/analyzer/inspections/functional.ts +0 -159
- package/src/analyzer/inspections/imperative.ts +0 -129
- package/src/analyzer/inspections/logic.ts +0 -166
- package/src/interpreter/components/FunctionRuntime.ts +0 -79
- package/src/interpreter/components/LazyRuntime.ts +0 -97
- package/src/interpreter/components/LogicEngine.ts +0 -227
- package/src/interpreter/components/LogicResolver.ts +0 -130
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import {
|
|
3
|
-
ArithmeticBinaryTable,
|
|
4
|
-
ComparisonOperationTable,
|
|
5
|
-
LogicalBinaryTable,
|
|
6
|
-
BitwiseBinaryTable,
|
|
7
|
-
StringOperationTable,
|
|
8
|
-
BitwiseUnaryTable,
|
|
9
|
-
LogicalUnaryTable,
|
|
10
|
-
ArithmeticUnaryTable,
|
|
11
|
-
ListBinaryTable,
|
|
12
|
-
ListUnaryTable,
|
|
13
|
-
} from "../../src/interpreter/components/Operations.js";
|
|
14
|
-
|
|
15
|
-
describe("Operations Tables", () => {
|
|
16
|
-
describe("ArithmeticBinaryTable", () => {
|
|
17
|
-
const ops = ArithmeticBinaryTable;
|
|
18
|
-
|
|
19
|
-
it("should perform basic arithmetic", () => {
|
|
20
|
-
expect(ops.Plus(2, 3)).to.equal(5);
|
|
21
|
-
expect(ops.Minus(5, 2)).to.equal(3);
|
|
22
|
-
expect(ops.Multiply(4, 2)).to.equal(8);
|
|
23
|
-
expect(ops.Divide(10, 2)).to.equal(5);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should calculate modulo", () => {
|
|
27
|
-
expect(ops.Modulo(10, 3)).to.equal(1); // 10 % 3 = 1
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should calculate power", () => {
|
|
31
|
-
expect(ops.Power(2, 3)).to.equal(8); // 2^3
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should find min and max", () => {
|
|
35
|
-
expect(ops.Min(10, 5)).to.equal(5);
|
|
36
|
-
expect(ops.Max(10, 5)).to.equal(10);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("ComparisonOperationTable", () => {
|
|
41
|
-
const ops = ComparisonOperationTable as any;
|
|
42
|
-
|
|
43
|
-
it("should handle equality and identity", () => {
|
|
44
|
-
expect(ops.Equal(5, "5")).to.be.true; // 5 == "5"
|
|
45
|
-
expect(ops.Equal(5, 6)).to.be.false;
|
|
46
|
-
|
|
47
|
-
expect(ops.Same(5, "5")).to.be.false; // 5 === "5"
|
|
48
|
-
expect(ops.Same(5, 5)).to.be.true;
|
|
49
|
-
|
|
50
|
-
expect(ops.NotEqual(5, 6)).to.be.true;
|
|
51
|
-
expect(ops.NotSame(5, "5")).to.be.true;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should handle numeric comparison", () => {
|
|
55
|
-
expect(ops.GreaterThan(10, 5)).to.be.true;
|
|
56
|
-
expect(ops.GreaterThan(5, 10)).to.be.false;
|
|
57
|
-
|
|
58
|
-
expect(ops.GreaterOrEqualThan(10, 10)).to.be.true;
|
|
59
|
-
|
|
60
|
-
expect(ops.LessThan(5, 10)).to.be.true;
|
|
61
|
-
expect(ops.LessOrEqualThan(10, 10)).to.be.true;
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("LogicalBinaryTable (Short-circuiting)", () => {
|
|
66
|
-
const ops = LogicalBinaryTable;
|
|
67
|
-
|
|
68
|
-
describe("And", () => {
|
|
69
|
-
it("should return true only if both are true", () => {
|
|
70
|
-
expect(ops.And(true, () => true)).to.be.true;
|
|
71
|
-
expect(ops.And(true, () => false)).to.be.false;
|
|
72
|
-
expect(ops.And(false, () => true)).to.be.false;
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("should NOT execute the right thunk if left is false", () => {
|
|
76
|
-
let executed = false;
|
|
77
|
-
const thunk = () => {
|
|
78
|
-
executed = true;
|
|
79
|
-
return true;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const result = ops.And(false, thunk);
|
|
83
|
-
|
|
84
|
-
expect(result).to.be.false;
|
|
85
|
-
expect(executed).to.be.false; // Short-circuit logic check
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("Or", () => {
|
|
90
|
-
it("should return true if at least one is true", () => {
|
|
91
|
-
expect(ops.Or(true, () => false)).to.be.true;
|
|
92
|
-
expect(ops.Or(false, () => true)).to.be.true;
|
|
93
|
-
expect(ops.Or(false, () => false)).to.be.false;
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should NOT execute the right thunk if left is true", () => {
|
|
97
|
-
let executed = false;
|
|
98
|
-
const thunk = () => {
|
|
99
|
-
executed = true;
|
|
100
|
-
return true;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const result = ops.Or(true, thunk);
|
|
104
|
-
|
|
105
|
-
expect(result).to.be.true;
|
|
106
|
-
expect(executed).to.be.false; // Short-circuit logic check
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("BitwiseBinaryTable", () => {
|
|
112
|
-
const ops = BitwiseBinaryTable;
|
|
113
|
-
|
|
114
|
-
it("should perform bitwise operations", () => {
|
|
115
|
-
expect(ops.BitwiseOr(1, 2)).to.equal(3); // 01 | 10 = 11 (3)
|
|
116
|
-
expect(ops.BitwiseAnd(3, 1)).to.equal(1); // 11 & 01 = 01 (1)
|
|
117
|
-
expect(ops.BitwiseXor(3, 1)).to.equal(2); // 11 ^ 01 = 10 (2)
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should perform shifts", () => {
|
|
121
|
-
expect(ops.BitwiseLeftShift(1, 2)).to.equal(4); // 1 << 2 = 4
|
|
122
|
-
expect(ops.BitwiseRightShift(4, 1)).to.equal(2); // 4 >> 1 = 2
|
|
123
|
-
expect(ops.BitwiseUnsignedRightShift(-10, 1)).to.equal(2147483643); // >>>
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("StringOperationTable", () => {
|
|
128
|
-
it("should concatenate strings", () => {
|
|
129
|
-
expect(StringOperationTable.Concat("Hello", " World")).to.equal(
|
|
130
|
-
"Hello World"
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should coerce numbers to strings during concatenation", () => {
|
|
135
|
-
// TS type says (string, string), but runtime JS behavior:
|
|
136
|
-
const op = StringOperationTable.Concat as any;
|
|
137
|
-
expect(op("Value: ", 10)).to.equal("Value: 10");
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("Unary Tables", () => {
|
|
142
|
-
it("BitwiseUnaryTable (Not)", () => {
|
|
143
|
-
// ~1 = -2 (Complemento a dos)
|
|
144
|
-
expect(BitwiseUnaryTable.BitwiseNot(1)).to.equal(-2);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("LogicalUnaryTable (Negation)", () => {
|
|
148
|
-
expect(LogicalUnaryTable.Negation(true)).to.be.false;
|
|
149
|
-
expect(LogicalUnaryTable.Negation(false)).to.be.true;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe("ArithmeticUnaryTable", () => {
|
|
153
|
-
const ops = ArithmeticUnaryTable;
|
|
154
|
-
it("should negate numbers", () => {
|
|
155
|
-
expect(ops.Negation(5)).to.equal(-5);
|
|
156
|
-
expect(ops.Negation(-5)).to.equal(5);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("should round numbers", () => {
|
|
160
|
-
expect(ops.Round(1.5)).to.equal(2);
|
|
161
|
-
expect(ops.Round(1.4)).to.equal(1);
|
|
162
|
-
expect(ops.Floor(1.9)).to.equal(1);
|
|
163
|
-
expect(ops.Ceil(1.1)).to.equal(2);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("should calc absolute and sqrt", () => {
|
|
167
|
-
expect(ops.Absolute(-10)).to.equal(10);
|
|
168
|
-
expect(ops.Sqrt(9)).to.equal(3);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe("List Tables", () => {
|
|
174
|
-
describe("ListBinaryTable", () => {
|
|
175
|
-
it("should concatenate arrays", () => {
|
|
176
|
-
const arr1 = [1, 2];
|
|
177
|
-
const arr2 = [3, 4];
|
|
178
|
-
const res = ListBinaryTable.Concat(arr1, arr2);
|
|
179
|
-
expect(res).to.deep.equal([1, 2, 3, 4]);
|
|
180
|
-
expect(arr1).to.have.length(2); // Ensure immutability (concat returns new array)
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe("ListUnaryTable", () => {
|
|
185
|
-
const ops = ListUnaryTable;
|
|
186
|
-
|
|
187
|
-
it("should return size of array", () => {
|
|
188
|
-
expect(ops.Size([1, 2, 3])).to.equal(3);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("should flatten nested arrays", () => {
|
|
192
|
-
// Flatten level 1 by default in .flat()
|
|
193
|
-
const input = [1, [2, 3], 4];
|
|
194
|
-
expect(ops.Flatten(input)).to.deep.equal([1, 2, 3, 4]);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe("DetectMax / DetectMin", () => {
|
|
198
|
-
// Nota: Estas pruebas asumen que 'isArrayOfNumbers' funciona correctamente
|
|
199
|
-
// o que se está usando la implementación real.
|
|
200
|
-
|
|
201
|
-
it("should detect max/min in number arrays", () => {
|
|
202
|
-
const nums = [10, 5, 20, 1];
|
|
203
|
-
expect(ops.DetectMax(nums)).to.equal(20);
|
|
204
|
-
expect(ops.DetectMin(nums)).to.equal(1);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("should throw if array contains non-numbers", () => {
|
|
208
|
-
const badInput = [10, "hello" as any, 20];
|
|
209
|
-
|
|
210
|
-
expect(() => ops.DetectMax(badInput)).to.throw(
|
|
211
|
-
/must be Array of numbers/
|
|
212
|
-
);
|
|
213
|
-
expect(() => ops.DetectMin(badInput)).to.throw(
|
|
214
|
-
/must be Array of numbers/
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import {
|
|
3
|
+
ArithmeticBinaryTable,
|
|
4
|
+
ComparisonOperationTable,
|
|
5
|
+
LogicalBinaryTable,
|
|
6
|
+
BitwiseBinaryTable,
|
|
7
|
+
StringOperationTable,
|
|
8
|
+
BitwiseUnaryTable,
|
|
9
|
+
LogicalUnaryTable,
|
|
10
|
+
ArithmeticUnaryTable,
|
|
11
|
+
ListBinaryTable,
|
|
12
|
+
ListUnaryTable,
|
|
13
|
+
} from "../../src/interpreter/components/Operations.js";
|
|
14
|
+
|
|
15
|
+
describe("Operations Tables", () => {
|
|
16
|
+
describe("ArithmeticBinaryTable", () => {
|
|
17
|
+
const ops = ArithmeticBinaryTable;
|
|
18
|
+
|
|
19
|
+
it("should perform basic arithmetic", () => {
|
|
20
|
+
expect(ops.Plus(2, 3)).to.equal(5);
|
|
21
|
+
expect(ops.Minus(5, 2)).to.equal(3);
|
|
22
|
+
expect(ops.Multiply(4, 2)).to.equal(8);
|
|
23
|
+
expect(ops.Divide(10, 2)).to.equal(5);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should calculate modulo", () => {
|
|
27
|
+
expect(ops.Modulo(10, 3)).to.equal(1); // 10 % 3 = 1
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should calculate power", () => {
|
|
31
|
+
expect(ops.Power(2, 3)).to.equal(8); // 2^3
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should find min and max", () => {
|
|
35
|
+
expect(ops.Min(10, 5)).to.equal(5);
|
|
36
|
+
expect(ops.Max(10, 5)).to.equal(10);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("ComparisonOperationTable", () => {
|
|
41
|
+
const ops = ComparisonOperationTable as any;
|
|
42
|
+
|
|
43
|
+
it("should handle equality and identity", () => {
|
|
44
|
+
expect(ops.Equal(5, "5")).to.be.true; // 5 == "5"
|
|
45
|
+
expect(ops.Equal(5, 6)).to.be.false;
|
|
46
|
+
|
|
47
|
+
expect(ops.Same(5, "5")).to.be.false; // 5 === "5"
|
|
48
|
+
expect(ops.Same(5, 5)).to.be.true;
|
|
49
|
+
|
|
50
|
+
expect(ops.NotEqual(5, 6)).to.be.true;
|
|
51
|
+
expect(ops.NotSame(5, "5")).to.be.true;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should handle numeric comparison", () => {
|
|
55
|
+
expect(ops.GreaterThan(10, 5)).to.be.true;
|
|
56
|
+
expect(ops.GreaterThan(5, 10)).to.be.false;
|
|
57
|
+
|
|
58
|
+
expect(ops.GreaterOrEqualThan(10, 10)).to.be.true;
|
|
59
|
+
|
|
60
|
+
expect(ops.LessThan(5, 10)).to.be.true;
|
|
61
|
+
expect(ops.LessOrEqualThan(10, 10)).to.be.true;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("LogicalBinaryTable (Short-circuiting)", () => {
|
|
66
|
+
const ops = LogicalBinaryTable;
|
|
67
|
+
|
|
68
|
+
describe("And", () => {
|
|
69
|
+
it("should return true only if both are true", () => {
|
|
70
|
+
expect(ops.And(true, () => true)).to.be.true;
|
|
71
|
+
expect(ops.And(true, () => false)).to.be.false;
|
|
72
|
+
expect(ops.And(false, () => true)).to.be.false;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should NOT execute the right thunk if left is false", () => {
|
|
76
|
+
let executed = false;
|
|
77
|
+
const thunk = () => {
|
|
78
|
+
executed = true;
|
|
79
|
+
return true;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const result = ops.And(false, thunk);
|
|
83
|
+
|
|
84
|
+
expect(result).to.be.false;
|
|
85
|
+
expect(executed).to.be.false; // Short-circuit logic check
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("Or", () => {
|
|
90
|
+
it("should return true if at least one is true", () => {
|
|
91
|
+
expect(ops.Or(true, () => false)).to.be.true;
|
|
92
|
+
expect(ops.Or(false, () => true)).to.be.true;
|
|
93
|
+
expect(ops.Or(false, () => false)).to.be.false;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should NOT execute the right thunk if left is true", () => {
|
|
97
|
+
let executed = false;
|
|
98
|
+
const thunk = () => {
|
|
99
|
+
executed = true;
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const result = ops.Or(true, thunk);
|
|
104
|
+
|
|
105
|
+
expect(result).to.be.true;
|
|
106
|
+
expect(executed).to.be.false; // Short-circuit logic check
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("BitwiseBinaryTable", () => {
|
|
112
|
+
const ops = BitwiseBinaryTable;
|
|
113
|
+
|
|
114
|
+
it("should perform bitwise operations", () => {
|
|
115
|
+
expect(ops.BitwiseOr(1, 2)).to.equal(3); // 01 | 10 = 11 (3)
|
|
116
|
+
expect(ops.BitwiseAnd(3, 1)).to.equal(1); // 11 & 01 = 01 (1)
|
|
117
|
+
expect(ops.BitwiseXor(3, 1)).to.equal(2); // 11 ^ 01 = 10 (2)
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should perform shifts", () => {
|
|
121
|
+
expect(ops.BitwiseLeftShift(1, 2)).to.equal(4); // 1 << 2 = 4
|
|
122
|
+
expect(ops.BitwiseRightShift(4, 1)).to.equal(2); // 4 >> 1 = 2
|
|
123
|
+
expect(ops.BitwiseUnsignedRightShift(-10, 1)).to.equal(2147483643); // >>>
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("StringOperationTable", () => {
|
|
128
|
+
it("should concatenate strings", () => {
|
|
129
|
+
expect(StringOperationTable.Concat("Hello", " World")).to.equal(
|
|
130
|
+
"Hello World"
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should coerce numbers to strings during concatenation", () => {
|
|
135
|
+
// TS type says (string, string), but runtime JS behavior:
|
|
136
|
+
const op = StringOperationTable.Concat as any;
|
|
137
|
+
expect(op("Value: ", 10)).to.equal("Value: 10");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("Unary Tables", () => {
|
|
142
|
+
it("BitwiseUnaryTable (Not)", () => {
|
|
143
|
+
// ~1 = -2 (Complemento a dos)
|
|
144
|
+
expect(BitwiseUnaryTable.BitwiseNot(1)).to.equal(-2);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("LogicalUnaryTable (Negation)", () => {
|
|
148
|
+
expect(LogicalUnaryTable.Negation(true)).to.be.false;
|
|
149
|
+
expect(LogicalUnaryTable.Negation(false)).to.be.true;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe("ArithmeticUnaryTable", () => {
|
|
153
|
+
const ops = ArithmeticUnaryTable;
|
|
154
|
+
it("should negate numbers", () => {
|
|
155
|
+
expect(ops.Negation(5)).to.equal(-5);
|
|
156
|
+
expect(ops.Negation(-5)).to.equal(5);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("should round numbers", () => {
|
|
160
|
+
expect(ops.Round(1.5)).to.equal(2);
|
|
161
|
+
expect(ops.Round(1.4)).to.equal(1);
|
|
162
|
+
expect(ops.Floor(1.9)).to.equal(1);
|
|
163
|
+
expect(ops.Ceil(1.1)).to.equal(2);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("should calc absolute and sqrt", () => {
|
|
167
|
+
expect(ops.Absolute(-10)).to.equal(10);
|
|
168
|
+
expect(ops.Sqrt(9)).to.equal(3);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("List Tables", () => {
|
|
174
|
+
describe("ListBinaryTable", () => {
|
|
175
|
+
it("should concatenate arrays", () => {
|
|
176
|
+
const arr1 = [1, 2];
|
|
177
|
+
const arr2 = [3, 4];
|
|
178
|
+
const res = ListBinaryTable.Concat(arr1, arr2);
|
|
179
|
+
expect(res).to.deep.equal([1, 2, 3, 4]);
|
|
180
|
+
expect(arr1).to.have.length(2); // Ensure immutability (concat returns new array)
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("ListUnaryTable", () => {
|
|
185
|
+
const ops = ListUnaryTable;
|
|
186
|
+
|
|
187
|
+
it("should return size of array", () => {
|
|
188
|
+
expect(ops.Size([1, 2, 3])).to.equal(3);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should flatten nested arrays", () => {
|
|
192
|
+
// Flatten level 1 by default in .flat()
|
|
193
|
+
const input = [1, [2, 3], 4];
|
|
194
|
+
expect(ops.Flatten(input)).to.deep.equal([1, 2, 3, 4]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("DetectMax / DetectMin", () => {
|
|
198
|
+
// Nota: Estas pruebas asumen que 'isArrayOfNumbers' funciona correctamente
|
|
199
|
+
// o que se está usando la implementación real.
|
|
200
|
+
|
|
201
|
+
it("should detect max/min in number arrays", () => {
|
|
202
|
+
const nums = [10, 5, 20, 1];
|
|
203
|
+
expect(ops.DetectMax(nums)).to.equal(20);
|
|
204
|
+
expect(ops.DetectMin(nums)).to.equal(1);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should throw if array contains non-numbers", () => {
|
|
208
|
+
const badInput = [10, "hello" as any, 20];
|
|
209
|
+
|
|
210
|
+
expect(() => ops.DetectMax(badInput)).to.throw(
|
|
211
|
+
/must be Array of numbers/
|
|
212
|
+
);
|
|
213
|
+
expect(() => ops.DetectMin(badInput)).to.throw(
|
|
214
|
+
/must be Array of numbers/
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|