Пример #1
1
 def test_buf(self):
     n3 = _build_gate.node()
     n3.str_set("01")
     n4 = _build_gate.node(_build_gate.mybuf, [n3])
     n4.no_run()
     print(n4)
     self.assertEqual(n4.__str__(), "00000000000000000000000000000001")
Пример #2
1
 def test_not(self):
     n3 = _build_gate.node()
     n3.str_set("01")
     n4 = _build_gate.node(_build_gate.mynot, [n3])
     n4.no_run()
     print(n4)
     self.assertEqual(n4.__str__(), "11111111111111111111111111111110")
Пример #3
1
def build_bench(c_input, c_logic, c_output):
    x_input = dict()
    x_logic = dict()
    x_output = dict()

    def build(t):
        gate = None
        if t in x_input:
            return x_input[t]
        elif t in x_logic:
            return x_logic[t]
        if c_logic[t][0] == "nand":
            gate = _build_gate.mynand
        elif c_logic[t][0] == "and":
            gate = _build_gate.myand
        elif c_logic[t][0] == "or":
            gate = _build_gate.myor
        elif c_logic[t][0] == "xor":
            gate = _build_gate.myxor
        elif c_logic[t][0] == "nor":
            gate = _build_gate.mynor
        elif c_logic[t][0] == "not":
            gate = _build_gate.mynot
        elif c_logic[t][0] == "buf":
            gate = _build_gate.mybuf
        ans = _build_gate.node(gate, [build(i) for i in c_logic[t][1]])
        x_logic[t] = ans
        return ans

    for i in c_input:
        x_input[i] = _build_gate.node()
    for i in c_output:
        x_output[i] = build(i)
    return x_input, x_logic, x_output
Пример #4
1
 def build(t):
     gate = None
     if t in x_input:
         return x_input[t]
     elif t in x_logic:
         return x_logic[t]
     if c_logic[t][0] == "nand":
         gate = _build_gate.mynand
     elif c_logic[t][0] == "and":
         gate = _build_gate.myand
     elif c_logic[t][0] == "or":
         gate = _build_gate.myor
     elif c_logic[t][0] == "xor":
         gate = _build_gate.myxor
     elif c_logic[t][0] == "nor":
         gate = _build_gate.mynor
     elif c_logic[t][0] == "not":
         gate = _build_gate.mynot
     elif c_logic[t][0] == "buf":
         gate = _build_gate.mybuf
     ans = _build_gate.node(gate, [build(i) for i in c_logic[t][1]])
     x_logic[t] = ans
     return ans
Пример #5
1
 def test_and(self):
     tem = set_up_two_node()
     n3 = _build_gate.node(_build_gate.myand, tem)
     n3.no_run()
     self.assertEqual(n3.__str__(), "00000000000000000000000000001000")
Пример #6
1
 def test_nand(self):
     tem = set_up_two_node()
     n3 = _build_gate.node(_build_gate.mynand, tem)
     n3.no_run()
     self.assertEqual(n3.__str__(), "11111111111111111111111111110111")
Пример #7
0
def set_up_two_node():
    n1 = _build_gate.node()
    n1.str_set("1100")
    n2 = _build_gate.node()
    n2.str_set("1010")
    return [n1, n2]
Пример #8
0
 def test_nor(self):
     tem = set_up_two_node()
     n3 = _build_gate.node(_build_gate.mynor, tem)
     n3.no_run()
     print(n3)
     self.assertEqual(n3.__str__(), "11111111111111111111111111110001")