28#include <nlohmann/json.hpp>
37class StringListTestComponent :
public Component {
39 static constexpr std::string_view Type =
"StringListTestComponent";
41 StringListTestComponent() :
Component({}, {})
43 defineStringListProperty(
"orientation",
"DOWN", {
"UP",
"DOWN",
"LEFT",
"RIGHT"});
46 std::string_view typeName()
const override {
return Type; }
47 void simulate(Simulator& sim)
override {}
52TEST(CircuitTest, EmptyCircuit)
60TEST(CircuitTest, SingleGateInputsOutputs)
62 auto a = std::make_shared<Wire>();
63 auto b = std::make_shared<Wire>();
64 auto o = std::make_shared<Wire>();
66 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
70 auto inputs = c.getInputs();
71 auto outputs = c.getOutputs();
73 EXPECT_EQ(inputs.size(), 2);
74 EXPECT_EQ(outputs.size(), 1);
75 EXPECT_EQ(inputs[0],
Bus({a}));
76 EXPECT_EQ(inputs[1],
Bus({b}));
77 EXPECT_EQ(outputs[0],
Bus({o}));
80TEST(CircuitTest, ResolvesGraphBackedComponentByVertexId)
82 auto component = std::make_shared<AndGate>();
83 Circuit circuit(component,
false);
85 const auto vertex = circuit.
getVertexId(component.get());
91TEST(CircuitTest, BoundaryComponentsDefineNamedInterface)
93 auto a = std::make_shared<Wire>();
94 auto b = std::make_shared<Wire>();
95 auto o = std::make_shared<Wire>();
97 Component_set components{std::make_shared<DummyInputComponent>(
Bus{a},
"data"),
98 std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o),
99 std::make_shared<DummyOutputComponent>(
Bus{o},
"result")};
100 Circuit circuit(components,
false);
104 ASSERT_EQ(inputs.size(), 1);
105 ASSERT_EQ(outputs.size(), 1);
106 EXPECT_EQ(inputs[0].name,
"data");
107 EXPECT_EQ(inputs[0].bus,
Bus({a}));
108 ASSERT_TRUE(inputs[0].boundaryVertex);
112 EXPECT_EQ(outputs[0].name,
"result");
113 EXPECT_EQ(outputs[0].bus,
Bus({o}));
114 ASSERT_TRUE(outputs[0].boundaryVertex);
118 EXPECT_EQ(circuit.
getInputs(), std::vector<Bus>({Bus{a}}));
119 EXPECT_EQ(circuit.getOutputs(), std::vector<Bus>({Bus{o}}));
122TEST(CircuitTest, BoundaryFallbackIsIndependentPerDirection)
124 auto a = std::make_shared<Wire>();
125 auto o = std::make_shared<Wire>();
126 Component_set components{std::make_shared<DummyInputComponent>(
Bus{a},
"data"),
127 std::make_shared<NotGate>(a, o)};
128 Circuit circuit(components,
false);
132 ASSERT_EQ(inputs.size(), 1);
133 ASSERT_EQ(outputs.size(), 1);
134 EXPECT_EQ(inputs[0].name,
"data");
135 EXPECT_EQ(outputs[0].name,
"output_0");
136 EXPECT_EQ(outputs[0].bus,
Bus({o}));
137 EXPECT_FALSE(outputs[0].boundaryVertex);
140TEST(CircuitTest, TwoGatesInternalWire)
142 auto a = std::make_shared<Wire>();
143 auto b = std::make_shared<Wire>();
144 auto mid = std::make_shared<Wire>();
145 auto o = std::make_shared<Wire>();
147 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
148 auto g2 = std::make_shared<NotGate>(mid, o);
159 EXPECT_EQ(inputs.size(), 2);
160 EXPECT_EQ(outputs.size(), 1);
161 EXPECT_EQ(inputs[0],
Bus({a}));
162 EXPECT_EQ(inputs[1],
Bus({b}));
163 EXPECT_EQ(outputs[0],
Bus({o}));
166TEST(CircuitTest, GetComponentsForBus)
168 auto a = std::make_shared<Wire>();
169 auto b = std::make_shared<Wire>();
170 auto mid = std::make_shared<Wire>();
171 auto o = std::make_shared<Wire>();
173 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
174 auto g2 = std::make_shared<NotGate>(mid, o);
176 auto busA =
Bus({a});
177 auto busB =
Bus({b});
178 auto busMid =
Bus({mid});
187 EXPECT_EQ(midComponents.size(), 2);
190 EXPECT_EQ(aComponents.size(), 1);
193TEST(CircuitTest, NotGateSingleInputOutput)
196 auto o = std::make_shared<Wire>();
198 auto g = std::make_shared<NotGate>(a, o);
205 EXPECT_EQ(inputs.size(), 1);
206 EXPECT_EQ(outputs.size(), 1);
207 EXPECT_EQ(inputs[0],
Bus({a}));
208 EXPECT_EQ(outputs[0],
Bus({o}));
211TEST(CircuitTest, ChangeInputsAfterConstruction)
213 auto a1 = std::make_shared<Wire>();
214 auto a2 = std::make_shared<Wire>();
215 auto o = std::make_shared<Wire>();
217 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a1, a2}, o);
221 EXPECT_EQ(c.getInputs().size(), 2);
222 EXPECT_EQ(c.getInputs()[0],
Bus({a1}));
223 EXPECT_EQ(c.getInputs()[1],
Bus({a2}));
225 auto b1 = std::make_shared<Wire>();
226 auto b2 = std::make_shared<Wire>();
228 g->setInput(0,
Bus({b1}));
229 g->setInput(1,
Bus({b2}));
231 auto inputs = c.getInputs();
232 EXPECT_EQ(inputs.size(), 2);
233 EXPECT_EQ(inputs[0],
Bus({b1}));
234 EXPECT_EQ(inputs[1],
Bus({b2}));
237TEST(CircuitTest, ChangeOutputAfterConstruction)
239 auto a = std::make_shared<Wire>();
240 auto b = std::make_shared<Wire>();
241 auto o1 = std::make_shared<Wire>();
243 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o1);
247 EXPECT_EQ(c.getOutputs().size(), 1);
248 EXPECT_EQ(c.getOutputs()[0],
Bus({o1}));
250 auto o2 = std::make_shared<Wire>();
251 g->setOutput(0,
Bus({o2}));
253 auto outputs = c.getOutputs();
254 EXPECT_EQ(outputs.size(), 1);
255 EXPECT_EQ(outputs[0],
Bus({o2}));
258TEST(CircuitTest, AddComponentToCircuit)
260 auto a = std::make_shared<Wire>();
261 auto o = std::make_shared<Wire>();
263 auto g = std::make_shared<NotGate>(a, o);
273 auto c2 = std::make_shared<Wire>();
274 auto g2 = std::make_shared<NotGate>(o, c2);
281 EXPECT_EQ(inputs.size(), 1);
282 EXPECT_EQ(outputs.size(), 1);
283 EXPECT_EQ(inputs[0],
Bus({a}));
284 EXPECT_EQ(outputs[0],
Bus({c2}));
289 auto a = std::make_shared<Wire>();
290 auto b = std::make_shared<Wire>();
291 auto o1 = std::make_shared<Wire>();
292 auto o2 = std::make_shared<Wire>();
294 auto inputBus =
Bus({a, b});
295 auto outputBus =
Bus({o1, o2});
297 struct TestComponent :
public Component {
298 TestComponent(std::vector<Bus> inputs, std::vector<Bus> outputs)
299 :
Component(std::move(inputs), std::move(outputs))
302 std::string_view
typeName()
const override {
return "TestComponent"; }
306 auto g = std::make_shared<TestComponent>(std::vector<Bus>{inputBus},
307 std::vector<Bus>{outputBus});
311 auto inputs = c.getInputs();
312 auto outputs = c.getOutputs();
314 EXPECT_EQ(inputs.size(), 1);
315 EXPECT_EQ(outputs.size(), 1);
316 EXPECT_EQ(inputs[0], inputBus);
317 EXPECT_EQ(outputs[0], outputBus);
318 EXPECT_EQ(inputs[0].size(), 2);
319 EXPECT_EQ(outputs[0].size(), 2);
322TEST(CircuitTest, ConnectionsExpandFanOut)
324 struct TestComponent :
public Component {
325 TestComponent(std::vector<Bus> inputs, std::vector<Bus> outputs)
326 :
Component(std::move(inputs), std::move(outputs))
329 std::string_view
typeName()
const override {
return "TestComponent"; }
333 auto fanout = std::make_shared<Wire>();
334 auto inverted = std::make_shared<Wire>();
336 auto source = std::make_shared<TestComponent>(std::vector<Bus>{},
337 std::vector<Bus>{
Bus({fanout})});
338 auto directSink = std::make_shared<TestComponent>(std::vector<Bus>{
Bus({fanout})},
340 auto notGate = std::make_shared<NotGate>(fanout, inverted);
341 auto invertedSink = std::make_shared<TestComponent>(std::vector<Bus>{
Bus({inverted})},
345 comps.insert(source);
346 comps.insert(directSink);
347 comps.insert(notGate);
348 comps.insert(invertedSink);
352 unsigned int fanoutConnectionCount = 0;
353 bool hasDirectSinkRoute =
false;
354 bool hasNotGateRoute =
false;
357 if (connection.source != source || connection.bus !=
Bus({fanout}))
360 ++fanoutConnectionCount;
361 hasDirectSinkRoute = hasDirectSinkRoute || connection.target == directSink;
362 hasNotGateRoute = hasNotGateRoute || connection.target == notGate;
363 EXPECT_EQ(connection.sourceBusIndex, 0);
364 EXPECT_EQ(connection.targetBusIndex, 0);
367 EXPECT_EQ(fanoutConnectionCount, 2);
368 EXPECT_TRUE(hasDirectSinkRoute);
369 EXPECT_TRUE(hasNotGateRoute);
372TEST(CircuitTest, ConnectionsPreserveSharedBusPortIndices)
374 struct TestComponent :
public Component {
375 TestComponent(std::vector<Bus> inputs, std::vector<Bus> outputs)
376 :
Component(std::move(inputs), std::move(outputs))
379 std::string_view
typeName()
const override {
return "TestComponent"; }
383 auto firstWire = std::make_shared<Wire>();
384 auto secondWire = std::make_shared<Wire>();
385 Bus sourceBus({firstWire, secondWire});
387 auto source = std::make_shared<TestComponent>(std::vector<Bus>{},
388 std::vector<Bus>{sourceBus, sourceBus});
389 auto target = std::make_shared<TestComponent>(
390 std::vector<Bus>{sourceBus,
Bus({firstWire})}, std::vector<Bus>{});
393 std::array<std::array<bool, 2>, 2> seenIndices{};
394 unsigned int connectionCount = 0;
396 if (connection.source != source || connection.target != target)
399 ASSERT_LT(connection.sourceBusIndex, seenIndices.size());
400 ASSERT_LT(connection.targetBusIndex, seenIndices.front().size());
401 seenIndices[connection.sourceBusIndex][connection.targetBusIndex] =
true;
405 EXPECT_EQ(connectionCount, 4);
406 for (
const auto& sourceIndices : seenIndices)
407 for (
const bool seen : sourceIndices)
411TEST(CircuitTest, GetSubgraphFanIn)
415 auto a = std::make_shared<Wire>();
416 auto b = std::make_shared<Wire>();
417 auto mid = std::make_shared<Wire>();
418 auto o = std::make_shared<Wire>();
420 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
421 auto g2 = std::make_shared<NotGate>(mid, o);
432 auto outputs = subCircuit.getOutputs();
434 EXPECT_EQ(inputs.size(), 2);
435 EXPECT_EQ(outputs.size(), 1);
436 EXPECT_EQ(outputs[0],
Bus({mid}));
439TEST(CircuitTest, GetSubgraphFanInThreeLevels)
443 auto a = std::make_shared<Wire>();
444 auto b = std::make_shared<Wire>();
445 auto c = std::make_shared<Wire>();
446 auto x = std::make_shared<Wire>();
447 auto y = std::make_shared<Wire>();
448 auto o = std::make_shared<Wire>();
450 auto not1 = std::make_shared<NotGate>(a, x);
451 auto and1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, y);
452 auto and2 = std::make_shared<AndGate>(std::vector<Wire_ptr>{y, c}, o);
465 auto outputs = subCircuit.getOutputs();
467 EXPECT_EQ(outputs.size(), 1);
468 EXPECT_EQ(outputs[0],
Bus({o}));
471 EXPECT_EQ(inputs.size(), 3);
474TEST(CircuitTest, GetSubgraphPartialFanIn)
478 auto a = std::make_shared<Wire>();
479 auto b = std::make_shared<Wire>();
480 auto c = std::make_shared<Wire>();
481 auto x = std::make_shared<Wire>();
482 auto y = std::make_shared<Wire>();
483 auto o = std::make_shared<Wire>();
485 auto not1 = std::make_shared<NotGate>(a, x);
486 auto and1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, y);
487 auto and2 = std::make_shared<AndGate>(std::vector<Wire_ptr>{y, c}, o);
499 auto outputs = subCircuit.getOutputs();
501 EXPECT_EQ(outputs.size(), 1);
502 EXPECT_EQ(outputs[0],
Bus({y}));
503 EXPECT_EQ(inputs.size(), 2);
506TEST(CircuitTest, GetForwardSubgraphFanOut)
510 auto a = std::make_shared<Wire>();
511 auto b = std::make_shared<Wire>();
512 auto x = std::make_shared<Wire>();
513 auto o = std::make_shared<Wire>();
515 auto not1 = std::make_shared<NotGate>(a, x);
516 auto and1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, o);
527 auto outputs = subCircuit.getOutputs();
529 EXPECT_EQ(inputs.size(), 2);
530 EXPECT_EQ(outputs.size(), 1);
531 EXPECT_EQ(outputs[0],
Bus({o}));
534TEST(CircuitTest, GetForwardSubgraphPartial)
538 auto a = std::make_shared<Wire>();
539 auto b = std::make_shared<Wire>();
540 auto x = std::make_shared<Wire>();
541 auto o = std::make_shared<Wire>();
543 auto not1 = std::make_shared<NotGate>(a, x);
544 auto and1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, o);
555 auto outputs = subCircuit.getOutputs();
557 EXPECT_EQ(inputs.size(), 2);
558 EXPECT_EQ(outputs.size(), 1);
559 EXPECT_EQ(outputs[0],
Bus({o}));
562TEST(CircuitTest, GetGraphNotEmpty)
564 auto a = std::make_shared<Wire>();
565 auto o = std::make_shared<Wire>();
567 auto g = std::make_shared<NotGate>(a, o);
571 EXPECT_GT(boost::num_vertices(c.
getGraph()), 0);
574TEST(CircuitTest, SplitDagAndNonDagPureDag)
577 auto a = std::make_shared<Wire>();
578 auto b = std::make_shared<Wire>();
579 auto mid = std::make_shared<Wire>();
580 auto o = std::make_shared<Wire>();
582 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
583 auto g2 = std::make_shared<NotGate>(mid, o);
594 ASSERT_EQ(blocks.size(), 1);
595 EXPECT_FALSE(blocks[0].isCyclic);
596 EXPECT_EQ(blocks[0].circuit.getInputs().size(), 2);
597 EXPECT_EQ(blocks[0].circuit.getOutputs().size(), 1);
598 EXPECT_EQ(blocks[0].circuit.getOutputs()[0],
Bus({o}));
601TEST(CircuitTest, SplitDagAndNonDagWithCycle)
606 auto ext = std::make_shared<Wire>();
607 auto w1 = std::make_shared<Wire>();
608 auto w2 = std::make_shared<Wire>();
610 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{w1, ext}, w2);
611 auto g2 = std::make_shared<NotGate>(w2, w1);
622 ASSERT_EQ(blocks.size(), 1);
623 EXPECT_TRUE(blocks[0].isCyclic);
624 EXPECT_EQ(boost::num_vertices(blocks[0].circuit.getGraph()), 2);
627TEST(CircuitTest, SplitDagAndNonDagMixed)
632 auto a = std::make_shared<Wire>();
633 auto b = std::make_shared<Wire>();
634 auto x = std::make_shared<Wire>();
635 auto y = std::make_shared<Wire>();
636 auto z = std::make_shared<Wire>();
638 auto g1 = std::make_shared<NotGate>(a, x);
639 auto g2 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, y);
640 auto g3 = std::make_shared<NotGate>(y, z);
641 auto g4 = std::make_shared<NotGate>(z, y);
654 ASSERT_EQ(blocks.size(), 2);
657 EXPECT_FALSE(blocks[0].isCyclic);
658 EXPECT_EQ(boost::num_vertices(blocks[0].circuit.getGraph()), 2);
661 EXPECT_TRUE(blocks[1].isCyclic);
662 EXPECT_EQ(boost::num_vertices(blocks[1].circuit.getGraph()), 2);
665TEST(CircuitTest, SplitDagAndNonDagEmpty)
670 EXPECT_TRUE(blocks.empty());
673TEST(CircuitTest, SerializeEmptyCircuit)
677 EXPECT_FALSE(serialized.empty());
679 auto json = nlohmann::json::parse(serialized);
680 EXPECT_EQ(json[
"components"].size(), 0);
681 EXPECT_EQ(json[
"version"], SILICON_VERSION);
682 EXPECT_FALSE(json.contains(
"description"));
685TEST(CircuitTest, SerializeSingleGate)
687 auto a = std::make_shared<Wire>();
688 auto b = std::make_shared<Wire>();
689 auto o = std::make_shared<Wire>();
691 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
695 auto serialized = c.serialize();
696 auto json = nlohmann::json::parse(serialized);
698 EXPECT_EQ(json[
"components"].size(), 1);
699 EXPECT_EQ(json[
"components"][0][
"type"],
"AndGate");
700 EXPECT_EQ(json[
"components"][0][
"inputs"].size(), 2);
701 EXPECT_EQ(json[
"components"][0][
"outputs"].size(), 1);
704TEST(CircuitTest, SerializeAllGateTypes)
706 auto in1 = std::make_shared<Wire>();
707 auto in2 = std::make_shared<Wire>();
708 auto out1 = std::make_shared<Wire>();
709 auto out2 = std::make_shared<Wire>();
710 auto out3 = std::make_shared<Wire>();
711 auto out4 = std::make_shared<Wire>();
712 auto out5 = std::make_shared<Wire>();
713 auto out6 = std::make_shared<Wire>();
715 auto andg = std::make_shared<AndGate>(std::vector<Wire_ptr>{in1, in2}, out1);
716 auto org = std::make_shared<OrGate>(std::vector<Wire_ptr>{in1, in2}, out2);
717 auto notg = std::make_shared<NotGate>(in1, out3);
718 auto nandg = std::make_shared<NandGate>(std::vector<Wire_ptr>{in1, in2}, out4);
719 auto norg = std::make_shared<NorGate>(std::vector<Wire_ptr>{in1, in2}, out5);
720 auto xorg = std::make_shared<XorGate>(std::array<Wire_ptr, 2>{in1, in2}, out6);
733 auto json = nlohmann::json::parse(serialized);
735 EXPECT_EQ(json[
"components"].size(), 6);
737 std::set<std::string> types;
738 for (
const auto& comp : json[
"components"]) {
739 types.insert(comp[
"type"]);
741 EXPECT_TRUE(types.contains(
"AndGate"));
742 EXPECT_TRUE(types.contains(
"OrGate"));
743 EXPECT_TRUE(types.contains(
"NotGate"));
744 EXPECT_TRUE(types.contains(
"NandGate"));
745 EXPECT_TRUE(types.contains(
"NorGate"));
746 EXPECT_TRUE(types.contains(
"XorGate"));
749TEST(CircuitTest, SerializeMultiWireBus)
751 auto a = std::make_shared<Wire>();
752 auto b = std::make_shared<Wire>();
753 auto o1 = std::make_shared<Wire>();
754 auto o2 = std::make_shared<Wire>();
756 auto inputBus =
Bus({a, b});
757 auto outputBus =
Bus({o1, o2});
759 struct TestComponent :
public Component {
760 TestComponent(std::vector<Bus> inputs, std::vector<Bus> outputs)
761 :
Component(std::move(inputs), std::move(outputs))
764 std::string_view
typeName()
const override {
return "MultiBusComponent"; }
768 auto g = std::make_shared<TestComponent>(std::vector<Bus>{inputBus},
769 std::vector<Bus>{outputBus});
773 auto serialized = c.serialize();
774 auto json = nlohmann::json::parse(serialized);
776 EXPECT_EQ(json[
"components"].size(), 1);
777 EXPECT_EQ(json[
"components"][0][
"type"],
"MultiBusComponent");
779 EXPECT_EQ(json[
"components"][0][
"inputs"].size(), 1);
780 EXPECT_EQ(json[
"components"][0][
"inputs"][0].size(), 2);
782 EXPECT_EQ(json[
"components"][0][
"outputs"].size(), 1);
783 EXPECT_EQ(json[
"components"][0][
"outputs"][0].size(), 2);
786TEST(CircuitTest, SerializeWireIdsAreValid)
788 auto a = std::make_shared<Wire>();
789 auto b = std::make_shared<Wire>();
790 auto o = std::make_shared<Wire>();
792 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
796 auto serialized = c.serialize();
797 auto json = nlohmann::json::parse(serialized);
799 for (
const auto& comp : json[
"components"]) {
800 for (
const auto& inputBus : comp[
"inputs"]) {
801 for (
const auto& wireId : inputBus) {
802 if (!wireId.is_null()) {
803 EXPECT_GE(wireId.get<uint64_t>(), 0);
807 for (
const auto& outputBus : comp[
"outputs"]) {
808 for (
const auto& wireId : outputBus) {
809 if (!wireId.is_null()) {
810 EXPECT_GE(wireId.get<uint64_t>(), 0);
817TEST(CircuitTest, ClearWiresLeavesDisconnectedPortsWithoutAllocatingWireIds)
819 auto a = std::make_shared<Wire>();
820 auto o = std::make_shared<Wire>();
821 auto g = std::make_shared<NotGate>(a, o);
825 auto firstJson = nlohmann::json::parse(first.
serialize());
829 auto secondJson = nlohmann::json::parse(second.
serialize());
831 ASSERT_EQ(firstJson[
"components"].size(), 1);
832 ASSERT_EQ(secondJson[
"components"].size(), 1);
833 EXPECT_EQ(firstJson[
"components"][0][
"inputs"][0][0],
nullptr);
834 EXPECT_EQ(firstJson[
"components"][0][
"outputs"][0][0],
nullptr);
835 EXPECT_EQ(secondJson[
"components"][0][
"inputs"][0][0],
nullptr);
836 EXPECT_EQ(secondJson[
"components"][0][
"outputs"][0][0],
nullptr);
837 EXPECT_EQ(firstJson[
"components"][0][
"inputs"], secondJson[
"components"][0][
"inputs"]);
838 EXPECT_EQ(firstJson[
"components"][0][
"outputs"],
839 secondJson[
"components"][0][
"outputs"]);
842TEST(CircuitTest, SerializeComplexCircuit)
844 auto i1 = std::make_shared<Wire>();
845 auto i2 = std::make_shared<Wire>();
846 auto i3 = std::make_shared<Wire>();
847 auto w1 = std::make_shared<Wire>();
848 auto w2 = std::make_shared<Wire>();
849 auto w3 = std::make_shared<Wire>();
850 auto w4 = std::make_shared<Wire>();
851 auto out = std::make_shared<Wire>();
853 auto n1 = std::make_shared<NotGate>(i1, w1);
854 auto n2 = std::make_shared<NotGate>(i2, w2);
855 auto a1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{w1, w2}, w3);
856 auto n3 = std::make_shared<NotGate>(w3, w4);
857 auto o1 = std::make_shared<OrGate>(std::vector<Wire_ptr>{w4, i3}, out);
869 auto json = nlohmann::json::parse(serialized);
871 EXPECT_EQ(json[
"components"].size(), 5);
872 EXPECT_TRUE(json.contains(
"version"));
875TEST(CircuitTest, DeserializeEmptyCircuit)
881 R
"({"version": ")" + std::string(SILICON_VERSION) + R"(", "components": []})";
885 EXPECT_EQ(boost::num_vertices(c.getGraph()), 0);
888TEST(CircuitTest, DeserializeSingleGate)
893 auto a = std::make_shared<Wire>();
894 auto b = std::make_shared<Wire>();
895 auto o = std::make_shared<Wire>();
897 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
900 auto serialized = original.serialize();
904 auto numVertices = boost::num_vertices(deserialized.getGraph());
905 EXPECT_EQ(numVertices, 1);
908TEST(CircuitTest, BusValuePropertiesRoundTripAsRawStringsAndRejectIntegers)
914 auto input = std::make_shared<DummyBusInputComponent>(
Bus(5),
"input");
918 auto serialized = nlohmann::json::parse(original.serialize());
919 for (
auto& component : serialized[
"components"]) {
921 EXPECT_EQ(component[
"properties"][
"value"],
"10X1");
924 EXPECT_EQ(component[
"properties"][
"startValue"],
"00101");
929 std::shared_ptr<ConstantComponent> restoredConstant;
930 std::shared_ptr<DummyBusInputComponent> restoredInput;
931 for (
const auto vertex :
932 boost::make_iterator_range(boost::vertices(restored.getGraph()))) {
933 const auto& component = restored.getGraph()[vertex].component;
934 if (
auto candidate = std::dynamic_pointer_cast<ConstantComponent>(component))
935 restoredConstant = std::move(candidate);
936 if (
auto candidate = std::dynamic_pointer_cast<DummyBusInputComponent>(component))
937 restoredInput = std::move(candidate);
939 ASSERT_TRUE(restoredConstant);
940 ASSERT_TRUE(restoredInput);
941 EXPECT_EQ(restoredConstant->getPropertyValue<
BusValue>(
"value"),
943 EXPECT_EQ(restoredInput->getPropertyValue<
BusValue>(
"startValue"),
946 for (
auto& component : serialized[
"components"]) {
948 component[
"properties"][
"value"] = 3;
950 component[
"properties"][
"startValue"] = 3;
956TEST(CircuitTest, BusValuePropertiesRoundTripZeroAndWideFourStateValues)
966 auto wideConstant = std::make_shared<ConstantComponent>(
Bus(130), wide);
970 const auto serialized = original.
serialize();
974 std::vector<BusValue> restoredValues;
975 for (
const auto vertex :
976 boost::make_iterator_range(boost::vertices(restored.getGraph()))) {
977 const auto constant = std::dynamic_pointer_cast<ConstantComponent>(
978 restored.getGraph()[vertex].component);
980 restoredValues.push_back(*constant->getPropertyValue<
BusValue>(
"value"));
983 EXPECT_TRUE(std::ranges::contains(restoredValues, wide));
987TEST(CircuitTest, DeserializePreservesWireIds)
992 auto a = std::make_shared<Wire>();
993 auto b = std::make_shared<Wire>();
994 auto o = std::make_shared<Wire>();
996 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
999 auto serialized = original.serialize();
1003 EXPECT_EQ(boost::num_vertices(deserialized.getGraph()), 1);
1006TEST(CircuitTest, DeserializeComplexCircuit)
1011 auto i1 = std::make_shared<Wire>();
1012 auto i2 = std::make_shared<Wire>();
1013 auto i3 = std::make_shared<Wire>();
1014 auto w1 = std::make_shared<Wire>();
1015 auto w2 = std::make_shared<Wire>();
1016 auto w3 = std::make_shared<Wire>();
1017 auto w4 = std::make_shared<Wire>();
1018 auto out = std::make_shared<Wire>();
1020 auto n1 = std::make_shared<NotGate>(i1, w1);
1021 auto n2 = std::make_shared<NotGate>(i2, w2);
1022 auto a1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{w1, w2}, w3);
1023 auto n3 = std::make_shared<NotGate>(w3, w4);
1024 auto o1 = std::make_shared<OrGate>(std::vector<Wire_ptr>{w4, i3}, out);
1033 Circuit original(comps,
false);
1038 auto numVertices = boost::num_vertices(deserialized.getGraph());
1039 EXPECT_EQ(numVertices, 5);
1042TEST(CircuitTest, DeserializeAllGateTypes)
1047 auto in1 = std::make_shared<Wire>();
1048 auto in2 = std::make_shared<Wire>();
1049 auto out1 = std::make_shared<Wire>();
1050 auto out2 = std::make_shared<Wire>();
1051 auto out3 = std::make_shared<Wire>();
1052 auto out4 = std::make_shared<Wire>();
1053 auto out5 = std::make_shared<Wire>();
1054 auto out6 = std::make_shared<Wire>();
1056 auto andg = std::make_shared<AndGate>(std::vector<Wire_ptr>{in1, in2}, out1);
1057 auto org = std::make_shared<OrGate>(std::vector<Wire_ptr>{in1, in2}, out2);
1058 auto notg = std::make_shared<NotGate>(in1, out3);
1059 auto nandg = std::make_shared<NandGate>(std::vector<Wire_ptr>{in1, in2}, out4);
1060 auto norg = std::make_shared<NorGate>(std::vector<Wire_ptr>{in1, in2}, out5);
1061 auto xorg = std::make_shared<XorGate>(std::array<Wire_ptr, 2>{in1, in2}, out6);
1067 comps.insert(nandg);
1071 Circuit original(comps,
false);
1076 EXPECT_EQ(boost::num_vertices(deserialized.getGraph()), 6);
1079TEST(CircuitTest, DeserializeMultiWireBus)
1084 auto in1 = std::make_shared<Wire>();
1085 auto in2 = std::make_shared<Wire>();
1086 auto out1 = std::make_shared<Wire>();
1087 auto out2 = std::make_shared<Wire>();
1089 auto andg1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{in1, in2}, out1);
1090 auto andg2 = std::make_shared<AndGate>(std::vector<Wire_ptr>{in1, in2}, out2);
1093 comps.insert(andg1);
1094 comps.insert(andg2);
1096 Circuit original(comps,
false);
1101 auto numVertices = boost::num_vertices(deserialized.getGraph());
1102 EXPECT_EQ(numVertices, 2);
1105TEST(CircuitTest, DeserializeHalfAdder)
1110 auto a = std::make_shared<Wire>();
1111 auto b = std::make_shared<Wire>();
1112 auto sum = std::make_shared<Wire>();
1113 auto cout = std::make_shared<Wire>();
1115 auto ha = std::make_shared<HalfAdder>(std::array<Wire_ptr, 2>{a, b}, sum, cout);
1118 auto serialized = original.serialize();
1122 EXPECT_EQ(boost::num_vertices(deserialized.getGraph()), 1);
1125TEST(CircuitTest, DeserializeAndNotGates)
1130 auto a = std::make_shared<Wire>();
1131 auto b = std::make_shared<Wire>();
1132 auto mid = std::make_shared<Wire>();
1133 auto out = std::make_shared<Wire>();
1135 auto andg = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
1136 auto notg = std::make_shared<NotGate>(mid, out);
1142 Circuit original(comps,
false);
1147 EXPECT_EQ(boost::num_vertices(deserialized.getGraph()), 2);
1150TEST(CircuitTest, SerializeIncludesProperties)
1152 auto a = std::make_shared<Wire>();
1153 auto o = std::make_shared<Wire>();
1155 auto g = std::make_shared<NotGate>(a, o);
1156 g->setProperty(
"delay", 2);
1161 auto json = nlohmann::json::parse(serialized);
1163 EXPECT_EQ(json[
"components"].size(), 1);
1164 EXPECT_TRUE(json[
"components"][0].contains(
"properties"));
1165 EXPECT_TRUE(json[
"components"][0][
"properties"].contains(
"delay"));
1166 EXPECT_EQ(json[
"components"][0][
"properties"][
"delay"], 2);
1169TEST(CircuitTest, DeserializeRestoresStringListProperty)
1172 registry.
registerType(std::string(StringListTestComponent::Type),
1173 [] {
return std::make_shared<StringListTestComponent>(); });
1175 auto component = std::make_shared<StringListTestComponent>();
1176 component->setProperty(
"orientation", std::string(
"LEFT"));
1178 Circuit original(component,
false);
1183 ASSERT_EQ(components.size(), 1);
1185 const auto restoredComponent = components.front();
1186 ASSERT_TRUE(restoredComponent);
1187 EXPECT_EQ(restoredComponent->getPropertyValue<std::string>(
"orientation").value(),
1191TEST(CircuitTest, DeserializeRestoresBitwiseGatePropertiesAndBusWidths)
1196 auto gate = std::make_shared<XorGate>(
1197 std::array<Wire_ptr, 2>{std::make_shared<Wire>(), std::make_shared<Wire>()},
1198 std::make_shared<Wire>());
1199 gate->setProperty(
"size", 4);
1200 gate->setProperty(
"bitwise",
true);
1202 Circuit original(gate,
false);
1207 ASSERT_EQ(components.size(), 1);
1209 const auto component = components.front();
1210 ASSERT_TRUE(component);
1211 EXPECT_EQ(component->typeName(),
"XorGate");
1212 EXPECT_EQ(component->getPropertyValue<
bool>(
"bitwise"),
true);
1213 EXPECT_EQ(component->getPropertyValue<
int>(
"size"), 4);
1214 ASSERT_EQ(component->getInputs().size(), 2);
1215 ASSERT_EQ(component->getOutputs().size(), 1);
1216 EXPECT_EQ(component->getInputs()[0].size(), 4);
1217 EXPECT_EQ(component->getInputs()[1].size(), 4);
1218 EXPECT_EQ(component->getOutputs()[0].size(), 4);
1221TEST(CircuitTest, DeserializeRestoresReductionGateAndModeChanges)
1225 auto gate = std::make_shared<AndGate>(
1226 std::vector<Wire_ptr>{std::make_shared<Wire>(), std::make_shared<Wire>()},
1227 std::make_shared<Wire>());
1228 gate->setProperty(
"size", 4);
1230 Circuit original(gate,
false);
1233 ASSERT_EQ(components.size(), 1);
1234 const auto component = components.front();
1235 ASSERT_EQ(component->inputBuses().size(), 1);
1236 EXPECT_EQ(component->inputBuses()[0].size(), 4);
1237 EXPECT_EQ(component->outputBuses()[0].size(), 1);
1238 component->setProperty(
"bitwise",
true);
1239 ASSERT_EQ(component->inputBuses().size(), 2);
1240 EXPECT_EQ(component->inputBuses()[0].size(), 4);
1241 EXPECT_EQ(component->inputBuses()[1].size(), 4);
1242 EXPECT_EQ(component->outputBuses()[0].size(), 4);
1245TEST(CircuitTest, DeserializeRestoresAdderNBitsSizeAndBusWidths)
1250 auto adder = std::make_shared<AdderNBits>(std::array<Bus, 2>{
Bus(4),
Bus(4)},
Bus(4),
1251 std::make_shared<Wire>());
1252 adder->setProperty(
"size", 8);
1254 Circuit original(adder,
false);
1259 ASSERT_EQ(components.size(), 1);
1261 const auto component = components.front();
1262 ASSERT_TRUE(component);
1263 EXPECT_EQ(component->typeName(),
"AdderNBits");
1264 EXPECT_EQ(component->getPropertyValue<
int>(
"size"), 8);
1265 ASSERT_EQ(component->getInputs().size(), 2);
1266 ASSERT_EQ(component->getOutputs().size(), 2);
1267 EXPECT_EQ(component->getInputs()[0].size(), 8);
1268 EXPECT_EQ(component->getInputs()[1].size(), 8);
1269 EXPECT_EQ(component->getOutputs()[0].size(), 8);
1270 EXPECT_EQ(component->getOutputs()[1].size(), 1);
1275 auto a = std::make_shared<Wire>();
1276 auto b = std::make_shared<Wire>();
1277 auto o = std::make_shared<Wire>();
1279 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
1283 EXPECT_EQ(c.getComponentsForBus(
Bus({a})).size(), 1);
1284 EXPECT_EQ(c.getComponentsForBus(
Bus({b})).size(), 1);
1285 EXPECT_EQ(c.getComponentsForBus(
Bus({o})).size(), 1);
1287 c.removeComponent(g);
1289 EXPECT_TRUE(c.getComponentsForBus(
Bus({a})).empty());
1290 EXPECT_TRUE(c.getComponentsForBus(
Bus({b})).empty());
1291 EXPECT_TRUE(c.getComponentsForBus(
Bus({o})).empty());
1294TEST(CircuitTest, RemoveComponentFromLargerCircuit)
1296 auto a = std::make_shared<Wire>();
1297 auto b = std::make_shared<Wire>();
1298 auto c1_out = std::make_shared<Wire>();
1299 auto c2_out = std::make_shared<Wire>();
1301 auto andg = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, c1_out);
1302 auto notg = std::make_shared<NotGate>(c1_out, c2_out);
1305 Circuit circuit(comps,
false);
1320TEST(CircuitTest, RemoveNonExistentComponentDoesNotCrash)
1322 auto a = std::make_shared<Wire>();
1323 auto o = std::make_shared<Wire>();
1324 auto g = std::make_shared<NotGate>(a, o);
1333TEST(CircuitTest, RemoveNullComponentDoesNotCrash)
1340TEST(CircuitTest, RemoveMiddleComponent)
1342 auto a = std::make_shared<Wire>();
1343 auto b = std::make_shared<Wire>();
1344 auto c = std::make_shared<Wire>();
1345 auto d = std::make_shared<Wire>();
1346 auto and_out = std::make_shared<Wire>();
1347 auto xor_out = std::make_shared<Wire>();
1348 auto or_out = std::make_shared<Wire>();
1350 auto andg = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, and_out);
1351 auto xorg = std::make_shared<XorGate>(std::array<Wire_ptr, 2>{and_out, c}, xor_out);
1352 auto org = std::make_shared<OrGate>(std::vector<Wire_ptr>{xor_out, d}, or_out);
1355 Circuit circuit(comps,
false);
1357 auto beforeInputs = circuit.
getInputs();
1360 EXPECT_EQ(beforeInputs.size(), 4);
1361 EXPECT_EQ(beforeOutputs.size(), 1);
1368 EXPECT_EQ(afterInputs.size(), 4);
1369 EXPECT_EQ(afterOutputs.size(), 2);
1376 EXPECT_TRUE(levelMap.empty());
1379TEST(CircuitTest, GetLevelMapSingleGate)
1381 auto a = std::make_shared<Wire>();
1382 auto b = std::make_shared<Wire>();
1383 auto o = std::make_shared<Wire>();
1385 auto g = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, o);
1389 auto levelMap = c.getLevelMap();
1390 ASSERT_EQ(levelMap.size(), 1);
1391 EXPECT_EQ(levelMap[g], 0);
1394TEST(CircuitTest, GetLevelMapTwoGatesSeries)
1396 auto a = std::make_shared<Wire>();
1397 auto b = std::make_shared<Wire>();
1398 auto mid = std::make_shared<Wire>();
1399 auto o = std::make_shared<Wire>();
1401 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, mid);
1402 auto g2 = std::make_shared<NotGate>(mid, o);
1411 ASSERT_EQ(levelMap.size(), 2);
1412 EXPECT_EQ(levelMap[g1], 0);
1413 EXPECT_EQ(levelMap[g2], 1);
1416TEST(CircuitTest, GetLevelMapThreeGatesSeries)
1418 auto a = std::make_shared<Wire>();
1419 auto b = std::make_shared<Wire>();
1420 auto x = std::make_shared<Wire>();
1421 auto y = std::make_shared<Wire>();
1422 auto o = std::make_shared<Wire>();
1424 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a, b}, x);
1425 auto g2 = std::make_shared<NotGate>(x, y);
1426 auto g3 = std::make_shared<NotGate>(y, o);
1436 ASSERT_EQ(levelMap.size(), 3);
1437 EXPECT_EQ(levelMap[g1], 0);
1438 EXPECT_EQ(levelMap[g2], 1);
1439 EXPECT_EQ(levelMap[g3], 2);
1442TEST(CircuitTest, GetLevelMapIndependentGates)
1444 auto a1 = std::make_shared<Wire>();
1445 auto b1 = std::make_shared<Wire>();
1446 auto o1 = std::make_shared<Wire>();
1447 auto a2 = std::make_shared<Wire>();
1448 auto o2 = std::make_shared<Wire>();
1450 auto g1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{a1, b1}, o1);
1451 auto g2 = std::make_shared<NotGate>(a2, o2);
1460 ASSERT_EQ(levelMap.size(), 2);
1461 EXPECT_EQ(levelMap[g1], 0);
1462 EXPECT_EQ(levelMap[g2], 0);
1465TEST(CircuitTest, GetLevelMapDiamond)
1470 auto a = std::make_shared<Wire>();
1471 auto b = std::make_shared<Wire>();
1472 auto x = std::make_shared<Wire>();
1473 auto o = std::make_shared<Wire>();
1475 auto g1 = std::make_shared<NotGate>(a, x);
1476 auto g2 = std::make_shared<AndGate>(std::vector<Wire_ptr>{x, b}, o);
1485 ASSERT_EQ(levelMap.size(), 2);
1486 EXPECT_EQ(levelMap[g1], 0);
1487 EXPECT_EQ(levelMap[g2], 1);
1490TEST(CircuitTest, GetLevelMapMultiplePathsDifferentDepths)
1496 auto a = std::make_shared<Wire>();
1497 auto b = std::make_shared<Wire>();
1498 auto w1 = std::make_shared<Wire>();
1499 auto w2 = std::make_shared<Wire>();
1500 auto w3 = std::make_shared<Wire>();
1501 auto o = std::make_shared<Wire>();
1503 auto n1 = std::make_shared<NotGate>(a, w1);
1504 auto n2 = std::make_shared<NotGate>(b, w2);
1505 auto a1 = std::make_shared<AndGate>(std::vector<Wire_ptr>{w1, w2}, w3);
1506 auto n3 = std::make_shared<NotGate>(w3, o);
1517 ASSERT_EQ(levelMap.size(), 4);
1518 EXPECT_EQ(levelMap[n1], 0);
1519 EXPECT_EQ(levelMap[n2], 0);
1520 EXPECT_EQ(levelMap[a1], 1);
1521 EXPECT_EQ(levelMap[n3], 2);
1524TEST(CircuitTest, BoundaryIdentitySurvivesVertexRebuildAndRoundTrip)
1526 auto a = std::make_shared<DummyInputComponent>(
Bus(1),
"same");
1527 auto b = std::make_shared<DummyInputComponent>(
Bus(1),
"same");
1528 const auto aId = a->portId();
1529 const auto bId = b->portId();
1530 ASSERT_NE(aId, bId);
1531 a->setProperty(
"name", std::string(
"renamed"));
1532 Circuit rebuilt(std::vector<Component_ptr>{b, a},
false);
1536 const auto ports = restored.getInputPorts();
1537 ASSERT_EQ(ports.size(), 2);
1538 EXPECT_EQ(ports[0].
id, bId);
1539 EXPECT_EQ(ports[1].
id, aId);
1540 EXPECT_EQ(ports[1].name,
"renamed");
1543TEST(CircuitTest, LegacyBoundaryIdentityIsStableBeforeFirstSave)
1547 const std::string legacy = R
"({"components":[
1548 {"id":0,"type":"DummyInputComponent","properties":{"name":"a"},
1549 "inputs":[],"outputs":[[10]]},
1550 {"id":1,"type":"DummyInputComponent","properties":{"name":"b"},
1551 "inputs":[],"outputs":[[11]]}]})";
1554 EXPECT_EQ(first.getInputPorts()[0].id, second.getInputPorts()[0].id);
1555 EXPECT_EQ(first.getInputPorts()[0].id, 1);
1556 EXPECT_EQ(first.getInputPorts()[1].id, 2);
1557 auto saved = nlohmann::json::parse(first.serialize());
1558 EXPECT_TRUE(saved[
"components"][0][
"portId"].is_number_unsigned());
1559 saved[
"components"][0][
"id"] = 1;
1560 saved[
"components"][1][
"id"] = 0;
1562 EXPECT_EQ(reordered.getInputPorts()[1].id, first.getInputPorts()[0].id);
1565TEST(CircuitTest, RejectsDuplicateBoundaryIdentities)
1567 auto a = std::make_shared<DummyInputComponent>(
Bus(1),
"a");
1568 auto b = std::make_shared<DummyInputComponent>(
Bus(1),
"b");
1569 b->setPortId(a->portId());
1570 Circuit circuit(std::vector<Component_ptr>{a, b},
false);
1571 EXPECT_THROW(
static_cast<void>(circuit.getInputPorts()), std::runtime_error);
1574TEST(CircuitTest, RejectsInvalidPersistedPortIds)
1578 auto document = nlohmann::json::parse(R
"({"components":[
1579 {"id":0,"type":"DummyInputComponent","portId":1,
1580 "properties":{"name":"a"},"inputs":[],"outputs":[[10]]}]})");
1582 for (
const auto& bad :
1583 {nlohmann::json(
"port:1"), nlohmann::json(
"legacy:1"),
1584 nlohmann::json(
"topology:0"), nlohmann::json(0), nlohmann::json(-1)}) {
1585 document[
"components"][0][
"portId"] = bad;
std::vector< Component_ptr > componentsIn(const Circuit &circuit)
Represents a digital circuit as a directed graph of components.
static Circuit deserialize(const std::string &jsonStr, const ComponentRegistry ®, const CircuitResolver *resolver=nullptr)
Deserializes the core circuit model from a JSON string.
std::optional< VertexDescriptor > getVertexId(const Component *component) const
Gets the vertex ID for a component.
Circuit getBackwardsSubgraph(const Bus &targetOutput) const
Extracts the cone of influence (COI) for a target output bus.
Component_ptr getComponentByVertexId(VertexDescriptor vertexId) const
Gets a component by its vertex ID.
std::vector< CircuitPort > getOutputPorts() const
Gets named output ports using boundary names or deterministic fallbacks.
const CircuitGraph & getGraph() const
Gets the underlying circuit graph.
Circuit getForwardSubgraph(const Bus &sourceInput) const
Extracts the forward cone of influence for a source input bus.
std::vector< SimulationBlock > splitCyclic() const
Splits the circuit into simulation blocks separating cyclic from acyclic parts.
std::string serialize() const
Serializes the core circuit model to a JSON string.
Circuit::LevelMap getLevelMap() const
Get a levelized map between the components and their level number.
std::vector< Bus > getOutputs() const
Gets all output buses of the circuit.
void addComponent(const Component_ptr &component)
Adds a component to the circuit recursively.
std::vector< CircuitPort > getInputPorts() const
Gets named input ports using boundary names or deterministic fallbacks.
Component_set getComponentsForBus(Bus b) const
Finds all components that are connected to a given bus.
std::vector< CircuitConnection > getConnections() const
Gets concrete output-to-input logical connections for routing.
void removeComponent(const Component_ptr &component)
Removes a component from the circuit.
std::vector< Bus > getInputs() const
Gets all input buses of the circuit.
static ComponentRegistry empty()
void registerType(std::string type, Factory factory)
Base class for all digital circuit components.
virtual std::string_view typeName() const =0
Gets the component type name.
virtual void simulate(SILICON::simulation::Simulator &sim)
Executes the component's logic.
static constexpr std::string_view Type
Executes event-driven simulation of a Circuit.
void registerAllComponents(ComponentRegistry ®istry)
std::set< Component_ptr, std::owner_less< Component_ptr > > Component_set
BusValue busValueFromBits(const std::string_view bits)
Strictly decodes an MSB-first raw string containing 0, 1, X, or E.
std::string formatValue(const BusValue &value, const BusValueFormat format, const std::size_t fixedWidth)
Format an LSB-first BusValue for display.
std::vector< State > BusValue
Directed logical connection between one component output bus and one input bus.
TEST(CircuitTest, EmptyCircuit)