Пример #1
0
 def obtener_reglas_para_sumador_de_2_bits_bit(self, bit):
     reglas = [
         [[0, 0, 0, 0], [0, 0, 0]],  # 0 + 0 = 0
         [[0, 0, 0, 1], [0, 0, 1]],  # 0 + 1 = 1
         [[0, 0, 1, 0], [0, 1, 0]],  # 0 + 2 = 2
         [[0, 0, 1, 1], [0, 1, 1]],  # 0 + 3 = 3
         [[0, 1, 0, 0], [0, 0, 1]],  # 1 + 0 = 1
         [[0, 1, 0, 1], [0, 1, 0]],  # 1 + 1 = 2
         [[0, 1, 1, 0], [0, 1, 1]],  # 1 + 2 = 3
         [[0, 1, 1, 1], [1, 0, 0]],  # 1 + 3 = 4
         [[1, 0, 0, 0], [0, 1, 0]],  # 2 + 0 = 2
         [[1, 0, 0, 1], [0, 1, 1]],  # 2 + 1 = 3
         [[1, 0, 1, 0], [1, 0, 0]],  # 2 + 2 = 4
         [[1, 0, 1, 1], [1, 0, 1]],  # 2 + 3 = 5
         [[1, 1, 0, 0], [0, 1, 1]],  # 3 + 0 = 3
         [[1, 1, 0, 1], [1, 0, 0]],  # 3 + 1 = 4
         [[1, 1, 1, 0], [1, 0, 1]],  # 3 + 2 = 5
         [[1, 1, 1, 1], [1, 1, 0]]
     ]  # 3 + 3 = 6
     reglasDeBitN = [[regla[0], regla[1][2 - bit]] for regla in reglas]
     self.puertas.append([circuitos.Or, circuitos.Or])
     self.puertas.append([circuitos.Xor, circuitos.Xor])
     self.fuentes.append([
         lambda l, r: circuitos.Fuente('C', self.entradas), circuitos.Fuente
     ])
     self.fuentes.append([
         lambda l, r: circuitos.Fuente('D', self.entradas), circuitos.Fuente
     ])
     return reglasDeBitN
Пример #2
0
 def setUpClass(cls):
     cls.entradas = dict()
     cls.puertas = [[circuitos.And, circuitos.And],
                    [lambda i1, i2: circuitos.Not(i1), circuitos.Not]]
     cls.fuentes = [[
         lambda i1, i2: circuitos.Fuente('A', cls.entradas),
         circuitos.Fuente
     ],
                    [
                        lambda i1, i2: circuitos.Fuente('B', cls.entradas),
                        circuitos.Fuente
                    ]]
Пример #3
0
 def test_generar_AxBxC(self):
     reglas = [[[False, False, False], False], [[False, False, True], True],
               [[False, True, False], True], [[False, True, True], False],
               [[True, False, False], True], [[True, False, True], False],
               [[True, True, False], False], [[True, True, True], True]]
     self.fuentes.append([
         lambda l, r: circuitos.Fuente('C', self.entradas), circuitos.Fuente
     ])
     self.puertas.append([circuitos.Or, circuitos.Or])
     self.encontrar_circuito(reglas, 12)