Skip to content

Commit 93fc8fe

Browse files
committed
test(logic): validate De Morgan's laws for boolean expressions
1 parent 8b6dd68 commit 93fc8fe

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

src/integration.boolean.test.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,31 +232,25 @@ describe("集成测试:布尔表达式", () => {
232232
expect(evaluate<boolean>(compiled, { a: false, b: false, c: true })).toBe(false);
233233
});
234234

235-
test("复杂逻辑表达式等价性", () => {
235+
test("德摩根定律验证", () => {
236236
const a = variable(z.boolean());
237237
const b = variable(z.boolean());
238-
const c = variable(z.boolean());
239-
240-
// (a && b) || c 与分步计算等价
241-
const step1 = expr({ a, b })("a && b");
242-
const combined = expr({ step1, c })("step1 || c");
243-
244-
const direct = expr({ a, b, c })("(a && b) || c");
245238

246-
const combinedCompiled = compile(combined, { a, b, c });
247-
const directCompiled = compile(direct, { a, b, c });
239+
// !(a && b) 等价于 !a || !b
240+
const leftCompiled = compile(expr({ a, b })("!(a && b)"), { a, b });
241+
const rightCompiled = compile(expr({ a, b })("(!a) || (!b)"), { a, b });
248242

249243
const testCases = [
250-
{ a: true, b: true, c: false },
251-
{ a: true, b: false, c: true },
252-
{ a: false, b: true, c: false },
253-
{ a: false, b: false, c: true },
244+
{ a: true, b: true },
245+
{ a: true, b: false },
246+
{ a: false, b: true },
247+
{ a: false, b: false },
254248
];
255249

256250
for (const values of testCases) {
257-
const combinedResult = evaluate<boolean>(combinedCompiled, values);
258-
const directResult = evaluate<boolean>(directCompiled, values);
259-
expect(combinedResult).toBe(directResult);
251+
const leftResult = evaluate<boolean>(leftCompiled, values);
252+
const rightResult = evaluate<boolean>(rightCompiled, values);
253+
expect(leftResult).toBe(rightResult);
260254
}
261255
});
262256
});

0 commit comments

Comments
 (0)