Skip to content

Commit

Permalink
Recognize 0 in customInitialValues (Strilanc#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
marwahaha authored Oct 15, 2020
1 parent 2978e99 commit 1f54b8e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/circuit/CircuitDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/circuit/CircuitDefinition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand Down

0 comments on commit 1f54b8e

Please sign in to comment.