From 1f54b8e536a2b1709d36f157727d2350fa67b7ba Mon Sep 17 00:00:00 2001 From: Kunal Marwaha Date: Wed, 14 Oct 2020 19:24:56 -0700 Subject: [PATCH] Recognize 0 in customInitialValues (#461) --- src/circuit/CircuitDefinition.js | 2 +- test/circuit/CircuitDefinition.test.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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-