Skip to content

Commit

Permalink
propagators/conditional.test -- fix switcher -- should not take outpu…
Browse files Browse the repository at this point in the history
…t as arg
  • Loading branch information
xieyuheng committed Sep 30, 2024
1 parent 3f5e0a0 commit 0c45f3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

> https://github.com/cicada-lang/propagator/issues/4
propagators/conditional.test

propagators/constant.test
propagators/boolean
propagators/boolean.test
Expand Down
15 changes: 15 additions & 0 deletions src/propagators/conditional.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from "node:test"
import { patch } from "../cell/index.js"
import { run } from "../scheduler/index.js"
import { conditional } from "./conditional.js"

test("propagators / conditional", async () => {
{
const [control, ifTrue, ifFalse, output] = conditional()
patch(control, true)
patch(ifFalse, 0)
patch(ifTrue, 1)
await run()
assert(output.content === 1)

Check failure on line 13 in src/propagators/conditional.test.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Cannot find name 'assert'.

Check failure on line 13 in src/propagators/conditional.test.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Cannot find name 'assert'.
}
})
8 changes: 4 additions & 4 deletions src/propagators/switcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nothing } from "../nothing/Nothing.js"
import { definePrimitive } from "../propagator/index.js"

// For `switch` is preserved by JavaScript.
export const switcher = definePrimitive(3, (control, input, output) => {
if (control) return input
else return output
})
export const switcher = definePrimitive(3, (control, input) =>
control ? input : nothing,
)

0 comments on commit 0c45f3f

Please sign in to comment.