From fb2d2f0e2cdfb5a7a1574b8db137bb280dcab1a0 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Mon, 30 Sep 2024 09:07:53 +0800 Subject: [PATCH] propagators/boolean -- conjoiner & disjoiner --- package-lock.json | 8 ++++---- package.json | 2 +- src/propagators/boolean.test.ts | 26 +++++++++++++++++++++----- src/propagators/boolean.ts | 4 +++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index ab56b02..0969ec3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,16 +9,16 @@ "version": "0.0.4", "license": "GPL-3.0-or-later", "devDependencies": { - "@types/node": "^22.7.1", + "@types/node": "^22.7.4", "prettier": "^3.3.3", "prettier-plugin-organize-imports": "^4.1.0", "typescript": "^5.6.2" } }, "node_modules/@types/node": { - "version": "22.7.1", - "resolved": "https://registry.npmmirror.com/@types/node/-/node-22.7.1.tgz", - "integrity": "sha512-adOMRLVmleuWs/5V/w5/l7o0chDK/az+5ncCsIapTKogsu/3MVWvSgP58qVTXi5IwpfGt8pMobNq9rOWtJyu5Q==", + "version": "22.7.4", + "resolved": "https://registry.npmmirror.com/@types/node/-/node-22.7.4.tgz", + "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 837be36..70b556d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "format": "prettier src --write" }, "devDependencies": { - "@types/node": "^22.7.1", + "@types/node": "^22.7.4", "prettier": "^3.3.3", "prettier-plugin-organize-imports": "^4.1.0", "typescript": "^5.6.2" diff --git a/src/propagators/boolean.test.ts b/src/propagators/boolean.test.ts index 176f160..6e44607 100644 --- a/src/propagators/boolean.test.ts +++ b/src/propagators/boolean.test.ts @@ -2,13 +2,29 @@ import assert from "node:assert" import test from "node:test" import { patch } from "../cell/index.js" import { run } from "../scheduler/index.js" -import { inverter } from "./boolean.js" +import { conjoiner, disjoiner, inverter } from "./boolean.js" test("propagators / boolean", async () => { - const [x, y] = inverter() - patch(x, true) + { + const [x, y] = inverter() + patch(x, true) + await run() + assert(y.content === false) + } - await run() + { + const [x, y, z] = conjoiner() + patch(x, true) + patch(y, false) + await run() + assert(z.content === false) + } - assert(y.content === false) + { + const [x, y, z] = disjoiner() + patch(x, true) + patch(y, false) + await run() + assert(z.content === true) + } }) diff --git a/src/propagators/boolean.ts b/src/propagators/boolean.ts index dfdcdbe..0457ee6 100644 --- a/src/propagators/boolean.ts +++ b/src/propagators/boolean.ts @@ -1,4 +1,6 @@ -import { not } from "../generics/index.js" +import { and, not, or } from "../generics/index.js" import { definePrimitive } from "../propagator/index.js" export const inverter = definePrimitive(2, not) +export const conjoiner = definePrimitive(3, and) +export const disjoiner = definePrimitive(3, or)