Skip to content

Commit 4ca2237

Browse files
committed
propagators/switcher.test
1 parent 9aa5f1a commit 4ca2237

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

TODO.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
> https://github.com/cicada-lang/propagator/issues/4
44
5-
propagators/switcher.test
6-
75
propagators/boolean -- inverter
86

97
propagators/conditional

src/propagators/switcher.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import assert from "node:assert"
2+
import test from "node:test"
3+
import { Belief, isBelief } from "../belief/Belief.js"
4+
import { beliefEqual } from "../belief/beliefEqual.js"
5+
import { patch } from "../cell/index.js"
6+
import { nothing } from "../nothing/index.js"
7+
import { run } from "../scheduler/index.js"
8+
import { switcher } from "./switcher.js"
9+
10+
test("propagators / switcher", async () => {
11+
const [control, input, output] = switcher()
12+
patch(input, 6)
13+
14+
await run()
15+
16+
assert.deepStrictEqual(output.content, nothing)
17+
patch(control, Belief(true, ["hello"]))
18+
19+
await run()
20+
21+
assert(
22+
isBelief(output.content) &&
23+
beliefEqual(output.content, Belief(6, ["hello"])),
24+
)
25+
})

src/propagators/switcher.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { definePrimitive } from "../propagator/index.js"
22

3+
// For `switch` is preserved by JavaScript.
34
export const switcher = definePrimitive(3, (control, input, output) => {
45
if (control) return input
56
else return output

0 commit comments

Comments
 (0)