Esempio n. 1
0
 def test_set_input(self):
     inputs = {'il': 0, 'i2': 1}
     or_gate = OrGate(inputs)
     or_gate.calculate_output()
     or_gate.set_input('i2', 0)
     or_gate.calculate_output()
     self.assertEqual(or_gate.get_output(), 0)
Esempio n. 2
0
class NorGate(Gate):

    def __init__(self, inputs: dict, gate_name: str = ""):
        self.__or_gate = OrGate(inputs)
        self.inputs = inputs
        self.name = gate_name

    def calculate_output(self):
        self.__or_gate.calculate_output()
        value = self.__or_gate.get_output()
        if value == 1:
            self.output = 0
        if value == 0:
            self.output = 1

    def get_output(self):
        return self.output

    def get_inputs(self):
        return self.__or_gate.get_inputs()

    def get_input(self, key: str):
        return self.__or_gate.get_input(key)

    def set_input(self, key: str, value: int):
        self.__or_gate.set_input(key, value)

    def get_name(self):
        return self.name
Esempio n. 3
0
 def build_gate(gate_type: str, gate_inputs: dict):
     return {
         'and': AndGate(gate_inputs),
         'buffer': BufferGate(gate_inputs),
         'inverter': InverterGate(gate_inputs),
         'nand': NandGate(gate_inputs),
         'nor': NorGate(gate_inputs),
         'or': OrGate(gate_inputs),
         'xor': XorGate(gate_inputs)
     }.get(gate_type, None)
Esempio n. 4
0
 def __init__(self, inputs: dict, gate_name: str = ""):
     self.__or_gate = OrGate(inputs)
     self.inputs = inputs
     self.name = gate_name
Esempio n. 5
0
 def test_or_simple_1(self):
     inputs = {'i1': 1, 'i2': 1}
     or_gate = OrGate(inputs)
     or_gate.calculate_output()
     self.assertEqual(or_gate.get_output(), 1)
Esempio n. 6
0
 def test_3_inputs_diff(self):
     inputs = {'i1': 0, 'i2': 1, 'i3': 0}
     or_gate = OrGate(inputs)
     or_gate.calculate_output()
     self.assertEqual(or_gate.get_output(), 1)