public void HalfAdder_Carry_Event() { // arrange var halfAdder = new HalfAdder("test"); halfAdder.V.V = VoltageSignal.HIGH; bool fired = false; halfAdder.Carry.Changed += _ => fired = true; // act, assert halfAdder.B.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- A: L; B: ^; no event"); halfAdder.B.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- A: L; B: -->H; no event"); halfAdder.B.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- A: L; B: v; no event"); halfAdder.B.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- A: L; B: -->L; no event"); halfAdder.A.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- B: L; A: ^; no event"); halfAdder.A.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- B: L; A: -->H; no event"); halfAdder.A.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- B: L; A: v; no event"); halfAdder.A.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- B: L; A: -->L; no event"); // setup halfAdder.A.V = VoltageSignal.HIGH; halfAdder.B.V = VoltageSignal.LOW; fired = false; // test halfAdder.B.V = VoltageSignal.HIGH; Assert.IsTrue(fired, "Gate on -- A: H; B: ^; event"); fired = false; halfAdder.B.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- A: H; B: -->H; no event"); halfAdder.B.V = VoltageSignal.LOW; Assert.IsTrue(fired, "Gate on -- A: H; B: v; event"); fired = false; halfAdder.B.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- A: H; B: -->L; no event"); // setup halfAdder.A.V = VoltageSignal.LOW; halfAdder.B.V = VoltageSignal.HIGH; fired = false; // test halfAdder.A.V = VoltageSignal.HIGH; Assert.IsTrue(fired, "Gate on -- B: H; A: ^; event"); fired = false; halfAdder.A.V = VoltageSignal.HIGH; Assert.IsFalse(fired, "Gate on -- B: H; A: -->H; no event"); halfAdder.A.V = VoltageSignal.LOW; Assert.IsTrue(fired, "Gate on -- B: H; A: v; event"); fired = false; halfAdder.A.V = VoltageSignal.LOW; Assert.IsFalse(fired, "Gate on -- B: H; A: -->L; no event"); }
private void CreateInternals() { this.half1 = new HalfAdder(this.PinA, this.PinB); this.bridge = new OrGate(this.PinC, this.PinC); this.half2 = new HalfAdder(); this.orGate = new OrGate(); }
public FullAdder(string name) { _halfAdder1 = new HalfAdder($"{name}-fulladder.in"); _halfAdder2 = new HalfAdder($"{name}-fulladder.sum"); _or = new OR($"{name}-fulladder.carry"); DoWireUp(); Components.Record(nameof(FullAdder)); }
public void perfect_gate_logic_test(double A, double B, double S, double Cout) { var halfAdder = new HalfAdder(TTLGateTypeEnum.Perfect); halfAdder.A.Add(A); halfAdder.B.Add(B); halfAdder.RunCircuit(); Assert.Equal(S, halfAdder.S(0)); Assert.Equal(Cout, halfAdder.Cout(0)); }
public void HalfAdder_Constructor() { var halfAdder = new HalfAdder("test"); Assert.AreEqual(VoltageSignal.LOW, halfAdder.V.V, "Constructor: V"); Assert.AreEqual(VoltageSignal.LOW, halfAdder.A.V, "Constructor: A"); Assert.AreEqual(VoltageSignal.LOW, halfAdder.B.V, "Constructor: B"); Assert.AreEqual(VoltageSignal.LOW, halfAdder.Sum.V, "Constructor: Sum"); Assert.AreEqual(VoltageSignal.LOW, halfAdder.Carry.V, "Constructor: Carry"); Assert.AreEqual("Sum: LOW; Carry: LOW", halfAdder.ToString(), "Constructor: ToString()"); }
public HalfAdderTest() { _halfAdder = new HalfAdder(); _power1 = new PowerSupplier(); _power2 = new PowerSupplier(); _lightSum = new IndicatorLight(); _lightCarry = new IndicatorLight(); _halfAdder.Number1In.ConnectTo(_power1.Output); _halfAdder.Number2In.ConnectTo(_power2.Output); _halfAdder.Sum.ConnectTo(_lightSum.Input); _halfAdder.CarryOut.ConnectTo(_lightCarry.Input); }
public void HalfAdder_Carry(VoltageSignal voltage, VoltageSignal a, VoltageSignal b, VoltageSignal expected) { // arrage var halfAdder = new HalfAdder("test"); // act halfAdder.V.V = voltage; halfAdder.A.V = a; halfAdder.B.V = b; // assert Assert.AreEqual(expected, halfAdder.Carry.V, $"V:{halfAdder.V.V}; A:{halfAdder.A.V}; B:{halfAdder.B.V}"); }
public FullAdder() { _orGate = new ORGate(); _halfAdderOrigin = new HalfAdder(); _halfAdderCarry = new HalfAdder(); _halfAdderCarry.CarryOut.ConnectTo(_orGate.Input1); _halfAdderOrigin.Sum.ConnectTo(_halfAdderCarry.Number2In); _halfAdderOrigin.CarryOut.ConnectTo(_orGate.Input2); CarryIn = _halfAdderCarry.Number1In; Number1In = _halfAdderOrigin.Number1In; Number2In = _halfAdderOrigin.Number2In; Sum = _halfAdderCarry.Sum; CarryOut = _orGate.Output; }
public void CreateNew() { IHalfAdder halfAdder = new HalfAdder(); Assert.IsNotNull(halfAdder); Assert.IsNotNull(halfAdder.Number1In); Assert.AreEqual(halfAdder.Number1In.LastReceivedSignal, 0); Assert.IsNotNull(halfAdder.Number2In); Assert.AreEqual(halfAdder.Number2In.LastReceivedSignal, 0); Assert.IsNotNull(halfAdder.Sum); Assert.AreEqual(halfAdder.Sum.LastSentSignal, 0); Assert.IsNotNull(halfAdder.CarryOut); Assert.AreEqual(halfAdder.CarryOut.LastSentSignal, 0); }
static void TritTest() { HalfAdder halfAdder = new HalfAdder(); halfAdder.CarryOutput += (s, t) => { Console.WriteLine($" Carry: {t.ToSymbol()}"); }; halfAdder.SumOutput += (s, t) => { Console.WriteLine($" Sum: {t.ToSymbol()}"); }; while (true) { Console.Write("Input A: "); if (TritEx.TryParse(Console.ReadLine(), out Trit trit)) { halfAdder.AInput(null, trit); } else { break; } Console.Write("Input B: "); if (TritEx.TryParse(Console.ReadLine(), out trit)) { halfAdder.BInput(null, trit); Console.WriteLine(); } else { break; } } Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); }
static void HalfAdderTest2() { var signalGenerator1 = new SignalGenerator(); var signalGenerator2 = new SignalGenerator(); bool signalHigh = true; bool longSignalHigh = true; for (int i = 0; i < 200; i++) { if (i % 20 == 0) { signalHigh = !signalHigh; } if (i % 40 == 0) { longSignalHigh = !longSignalHigh; } signalGenerator1.AddSample(signalHigh ? 5 : 0); signalGenerator2.AddSample(longSignalHigh ? 5 : 0); } var adder1Circuit = new HalfAdder(TTLGateTypeEnum.LS); for (int i = 0; i < 200; i++) { adder1Circuit.A.Add(signalGenerator1.Output(i)); adder1Circuit.B.Add(signalGenerator2.Output(i)); } adder1Circuit.RunCircuit(); for (int i = 0; i < 200; i++) { _logger.Debug($"T:{i:000} IN1:{signalGenerator1.Output(i)} IN2:{signalGenerator2.Output(i)} S:{adder1Circuit.S(i)} C:{adder1Circuit.Cout(i)}"); } }
public void HalfAdderSumsCorrectly() { //Given var halfAdder = new HalfAdder(); var table = new List <bool4> { new bool4(false, false, false, false), new bool4(false, true, true, false), new bool4(true, false, true, false), new bool4(true, true, false, true), }; foreach (var t in table) { //When halfAdder.InputA.State = t.Item1; halfAdder.InputB.State = t.Item2; //Then halfAdder.Sum.State.Should().Be(t.Item3); halfAdder.CarryOver.State.Should().Be(t.Item4); } }
public List <StandardComponent> parcourir_copier() { UIElement[] tableau = new UIElement[1000]; List <StandardComponent> liste = new List <StandardComponent>(); int length = canvas.Children.Count; canvas.Children.CopyTo(tableau, 0); for (int i = 0; i < length; i++) { StandardComponent newChild = null; if (!(typeof(Line) == tableau[i].GetType()) && ((tableau[i] as StandardComponent).IsSelect)) { if (typeof(AND) == tableau[i].GetType()) { newChild = new AND((tableau[i] as AND).nbrInputs()); for (int j = 0; j < (tableau[i] as AND).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as AND).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as AND).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(OR) == tableau[i].GetType()) { newChild = new OR((tableau[i] as OR).nbrInputs()); for (int j = 0; j < (tableau[i] as OR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as OR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as OR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(NAND) == tableau[i].GetType()) { newChild = new NAND((tableau[i] as NAND).nbrInputs()); for (int j = 0; j < (tableau[i] as NAND).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as NAND).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as NAND).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(NOR) == tableau[i].GetType()) { newChild = new NOR((tableau[i] as NOR).nbrInputs()); for (int j = 0; j < (tableau[i] as NOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as NOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as NOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(Not) == tableau[i].GetType()) { newChild = new Not(); Terminal terminal_1 = (Terminal)((tableau[i] as Not).inputStack.Children[0]); Terminal terminal_2 = (Terminal)((newChild as Not).inputStack.Children[0]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } else if (typeof(Output) == tableau[i].GetType()) { newChild = new Output(); } else if (typeof(Input) == tableau[i].GetType()) { newChild = new Input(); (newChild as Input).state = (tableau[i] as Input).state; } else if (typeof(XNOR) == tableau[i].GetType()) { newChild = new XNOR((tableau[i] as XNOR).nbrInputs()); for (int j = 0; j < (tableau[i] as XNOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as XNOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as XNOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(XOR) == tableau[i].GetType()) { newChild = new XOR((tableau[i] as XOR).nbrInputs()); for (int j = 0; j < (tableau[i] as XOR).nbrInputs(); j++) { Terminal terminal_1 = (Terminal)((tableau[i] as XOR).inputStack.Children[j]); Terminal terminal_2 = (Terminal)((newChild as XOR).inputStack.Children[j]); if (terminal_1.IsInversed) { terminal_2.IsInversed = true; terminal_2.input_inversed(); } } } else if (typeof(Comparateur) == tableau[i].GetType()) { newChild = new Comparateur((tableau[i] as Comparateur).nbrInputs(), (tableau[i] as Comparateur).nbrOutputs()); } else if (typeof(Decodeur) == tableau[i].GetType()) { newChild = new Decodeur((tableau[i] as Decodeur).nbrInputs(), (tableau[i] as Decodeur).nbrOutputs()); } else if (typeof(Demultiplexer) == tableau[i].GetType()) { newChild = new Demultiplexer((tableau[i] as Demultiplexer).nbrInputs(), (tableau[i] as Demultiplexer).nbrOutputs(), (tableau[i] as Demultiplexer).nbrSelections()); } else if (typeof(Encodeur) == tableau[i].GetType()) { newChild = new Encodeur((tableau[i] as Encodeur).nbrInputs(), (tableau[i] as Encodeur).nbrOutputs()); } else if (typeof(FullAdder) == tableau[i].GetType()) { newChild = new FullAdder((tableau[i] as FullAdder).nbrInputs(), (tableau[i] as FullAdder).nbrOutputs()); } else if (typeof(FullSub) == tableau[i].GetType()) { newChild = new FullSub((tableau[i] as FullSub).nbrInputs(), (tableau[i] as FullSub).nbrOutputs()); } else if (typeof(HalfAdder) == tableau[i].GetType()) { newChild = new HalfAdder((tableau[i] as HalfAdder).nbrInputs(), (tableau[i] as HalfAdder).nbrOutputs()); } else if (typeof(HalfSub) == tableau[i].GetType()) { newChild = new HalfSub((tableau[i] as HalfSub).nbrInputs(), (tableau[i] as HalfSub).nbrOutputs()); } else if (typeof(Multiplexer) == tableau[i].GetType()) { newChild = new Multiplexer((tableau[i] as Multiplexer).nbrInputs(), (tableau[i] as Multiplexer).nbrOutputs(), (tableau[i] as Multiplexer).nbrSelections()); } else if (typeof(SequentialComponent.Clock) == tableau[i].GetType()) { newChild = new SequentialComponent.Clock((tableau[i] as SequentialComponent.Clock).LowLevelms, (tableau[i] as SequentialComponent.Clock).HighLevelms, MainWindow.Delay); } liste.Add(newChild); newChild.AllowDrop = true; newChild.PreviewMouseLeftButtonDown += fenetre.MouseLeftButtonDown; newChild.PreviewMouseMove += fenetre.MouseMove; newChild.PreviewMouseLeftButtonUp += fenetre.PreviewMouseLeftButtonUp; newChild.SetValue(Canvas.LeftProperty, tableau[i].GetValue(Canvas.LeftProperty)); newChild.SetValue(Canvas.TopProperty, tableau[i].GetValue(Canvas.TopProperty)); (newChild as StandardComponent).PosX = (tableau[i] as StandardComponent).PosX; (newChild as StandardComponent).PosY = (tableau[i] as StandardComponent).PosY; try { StandardComponent component = newChild as StandardComponent; component.recalculer_pos(); } catch { }; } } return(liste); }
/* ========================================================================================= * Create 1-Bit Components * ========================================================================================= */ private void halfAdderToolStripMenuItem_Click(object sender, EventArgs e) { HalfAdder ha = new HalfAdder(); ha.Location = calcLocation(); ha.Size = s.Equals(LogicGate.small) ? LGComponent.small : s.Equals(LogicGate.medium) ? LGComponent.medium : LGComponent.large; ha.Font = new Font(ha.Font.FontFamily, fs); ha.Name = ha.GetType().Name + namecntr++; this.Controls.Add(ha); }
static void Main(string[] args) { WireSet ws = new WireSet(9); WireSet ws2 = new WireSet(9); WireSet ws3 = new WireSet(9); OrGate or = new OrGate(); XorGate xor = new XorGate(); MultiBitAndGate mbag3 = new MultiBitAndGate(3); MultiBitAndGate mbag4 = new MultiBitAndGate(4); MultiBitAndGate mbag5 = new MultiBitAndGate(5); MultiBitAndGate mbag6 = new MultiBitAndGate(6); MultiBitAndGate mbag7 = new MultiBitAndGate(7); MultiBitAndGate mbag8 = new MultiBitAndGate(8); MultiBitOrGate mbog3 = new MultiBitOrGate(3); MultiBitOrGate mbog4 = new MultiBitOrGate(4); MultiBitOrGate mbog5 = new MultiBitOrGate(5); MultiBitOrGate mbog6 = new MultiBitOrGate(6); MultiBitOrGate mbog7 = new MultiBitOrGate(7); MultiBitOrGate mbog8 = new MultiBitOrGate(8); MuxGate mg = new MuxGate(); Demux dmg = new Demux(); BitwiseOrGate bwog0 = new BitwiseOrGate(0); BitwiseOrGate bwog1 = new BitwiseOrGate(1); BitwiseOrGate bwog2 = new BitwiseOrGate(2); BitwiseOrGate bwog3 = new BitwiseOrGate(3); BitwiseOrGate bwog4 = new BitwiseOrGate(4); BitwiseOrGate bwog5 = new BitwiseOrGate(5); BitwiseOrGate bwog6 = new BitwiseOrGate(6); BitwiseOrGate bwog7 = new BitwiseOrGate(7); BitwiseAndGate bwag2 = new BitwiseAndGate(2); BitwiseAndGate bwag3 = new BitwiseAndGate(3); BitwiseAndGate bwag4 = new BitwiseAndGate(4); BitwiseNotGate bwng2 = new BitwiseNotGate(2); BitwiseNotGate bwng3 = new BitwiseNotGate(3); BitwiseNotGate bwng4 = new BitwiseNotGate(4); BitwiseDemux bwdm2 = new BitwiseDemux(2); BitwiseDemux bwdm3 = new BitwiseDemux(3); BitwiseDemux bwdm4 = new BitwiseDemux(4); BitwiseMux bwmx2 = new BitwiseMux(2); BitwiseMux bwmx3 = new BitwiseMux(3); BitwiseMux bwmx4 = new BitwiseMux(4); BitwiseMultiwayMux bwmwm = new BitwiseMultiwayMux(3, 3); BitwiseMultiwayDemux bwmwdm = new BitwiseMultiwayDemux(3, 3); HalfAdder ha = new HalfAdder(); FullAdder fa = new FullAdder(); MultiBitAdder mba = new MultiBitAdder(4); ALU alu = new ALU(4); System.Console.WriteLine(or.TestGate().ToString()); System.Console.WriteLine(xor.TestGate().ToString()); System.Console.WriteLine(mbag3.TestGate().ToString()); System.Console.WriteLine(mbag4.TestGate().ToString()); System.Console.WriteLine(mbag5.TestGate().ToString()); System.Console.WriteLine(mbag6.TestGate().ToString()); System.Console.WriteLine(mbag7.TestGate().ToString()); System.Console.WriteLine(mbag8.TestGate().ToString()); System.Console.WriteLine(mbog3.TestGate().ToString()); System.Console.WriteLine(mbog4.TestGate().ToString()); System.Console.WriteLine(mbog5.TestGate().ToString()); System.Console.WriteLine(mbog6.TestGate().ToString()); System.Console.WriteLine(mbog7.TestGate().ToString()); System.Console.WriteLine(mbog8.TestGate().ToString()); System.Console.WriteLine(mg.TestGate().ToString()); System.Console.WriteLine(dmg.TestGate().ToString()); System.Console.WriteLine(bwag2.TestGate().ToString()); System.Console.WriteLine(bwag3.TestGate().ToString()); System.Console.WriteLine(bwag4.TestGate().ToString()); System.Console.WriteLine(bwog0.TestGate().ToString()); System.Console.WriteLine(bwog1.TestGate().ToString()); System.Console.WriteLine(bwog2.TestGate().ToString()); System.Console.WriteLine(bwog3.TestGate().ToString()); System.Console.WriteLine(bwog4.TestGate().ToString()); System.Console.WriteLine(bwog5.TestGate().ToString()); System.Console.WriteLine(bwog6.TestGate().ToString()); System.Console.WriteLine(bwog7.TestGate().ToString()); ws.Set2sComplement(-5); System.Console.WriteLine(ws.Get2sComplement().ToString()); int test = 0; int test2 = 0; for (int i = 1; i < 50; i++) { ws2.SetValue(i); if (ws2.GetValue() != i) { test = 10; } } for (int i = -34; i < 50; i++) { ws3.Set2sComplement(i); if (ws3.Get2sComplement() != i) { test2 = 10; } } System.Console.WriteLine(test); System.Console.WriteLine(test2); System.Console.WriteLine(bwng2.TestGate().ToString()); System.Console.WriteLine(bwng3.TestGate().ToString()); System.Console.WriteLine(bwng4.TestGate().ToString()); System.Console.WriteLine(bwdm2.TestGate().ToString()); System.Console.WriteLine(bwdm3.TestGate().ToString()); System.Console.WriteLine(bwdm4.TestGate().ToString()); System.Console.WriteLine(bwmx2.TestGate().ToString()); System.Console.WriteLine(bwmx3.TestGate().ToString()); System.Console.WriteLine(bwmx4.TestGate().ToString()); System.Console.WriteLine(bwmwm.TestGate().ToString()); System.Console.WriteLine(bwmwdm.TestGate().ToString()); System.Console.WriteLine(ha.TestGate().ToString()); System.Console.WriteLine(fa.TestGate().ToString()); System.Console.WriteLine(mba.TestGate().ToString()); System.Console.WriteLine(alu.TestGate().ToString()); }