Skip to content

Commit

Permalink
propagators/boolean -- conjoiner & disjoiner
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 30, 2024
1 parent e1b4849 commit fb2d2f0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 21 additions & 5 deletions src/propagators/boolean.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
4 changes: 3 additions & 1 deletion src/propagators/boolean.ts
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fb2d2f0

Please sign in to comment.