diff --git a/src/circuit/CircuitDefinition.js b/src/circuit/CircuitDefinition.js index fdfa7839..085a0064 100644 --- a/src/circuit/CircuitDefinition.js +++ b/src/circuit/CircuitDefinition.js @@ -153,7 +153,7 @@ class CircuitDefinition { if (newStateIndex !== undefined) { newVal = newStateIndex; } - if (newVal === undefined) { + if (newVal === undefined || newVal === 0) { m.delete(wire); } else { m.set(wire, newVal); diff --git a/test/circuit/CircuitDefinition.test.js b/test/circuit/CircuitDefinition.test.js index bab7788b..0024c07e 100644 --- a/test/circuit/CircuitDefinition.test.js +++ b/test/circuit/CircuitDefinition.test.js @@ -1310,6 +1310,21 @@ suite.test("gateAtLocIsDisabledReason_multiwireOperations", () => { }); +suite.test("withSwitchedInitialStateOn", () => { + let c = circuit(`- + -`); + assertThat(c.customInitialValues).isEqualTo(new Map()); + + c = c.withSwitchedInitialStateOn(0); + assertThat(c.customInitialValues).isEqualTo(new Map([[0, '1']])); + + c = c.withSwitchedInitialStateOn(0); + assertThat(c.customInitialValues).isEqualTo(new Map([[0, '+']])); + + c = c.withSwitchedInitialStateOn(0, 0); + assertThat(c.customInitialValues).isEqualTo(new Map()); +}); + suite.test("colCustomContextFromGates", () => { let c = circuit(`-A-B- -A-A-