Ejemplo n.º 1
0
def test_find():
    n = core.Network()
    a = gates.Switch(n)
    b = gates.Switch(n)
    c = gates.Switch(n)
    r, co = adders.full_adder(a, b, c)
    assert a.find("full_adder(0.half_adder(0.and.1).or.1)") is co
    assert a.find("full_adder(0.half_adder(0.not.and.or.0).half_adder(0.not.and.or.0).0)") is r
Ejemplo n.º 2
0
def test_short_cut_find():
    n = core.Network()
    a = gates.Switch(n)
    b = gates.Switch(n)
    c = gates.Switch(n)
    r, co = adders.full_adder(a, b, c)
    assert a.find("full_adder(0.1)") is co
    assert a.find("full_adder(0.0)") is r
Ejemplo n.º 3
0
def test_list():
    n = core.Network()
    a = gates.Switch(n)
    b = gates.Switch(n)
    c = gates.Switch(n)
    r, co = adders.full_adder(a, b, c)
    assert a.list("") == ["full_adder(0"]
    assert a.list("full_adder(0") == ["0)", "1)", "half_adder(0"]
    assert a.list("full_adder(0.half_adder(0") == ["0)", "1)", "and", "and", "not"]
    assert a.list("full_adder(0.half_adder(0.and") == ["1)"]
    assert a.list("full_adder(0.half_adder(0.and.1)") == ["or"]
    assert a.list("full_adder(0.half_adder(0.and.1).or") == ["1)"]
    assert a.list("full_adder(0.half_adder(0.and.1).or.1)") == []
Ejemplo n.º 4
0
def test_full_adder():
    network = core.Network()
    a = gates.Switch(network)
    b = gates.Switch(network)
    c = gates.Switch(network)
    r, co = adders.full_adder(a, b, c)
    network.drain()

    a.write(False)
    b.write(False)
    c.write(False)
    network.drain()
    assert not r.read()
    assert not co.read()

    a.write(True)
    b.write(False)
    c.write(False)
    network.drain()
    assert r.read()
    assert not co.read()

    a.write(False)
    b.write(True)
    c.write(False)
    network.drain()
    assert r.read()
    assert not co.read()

    a.write(True)
    b.write(True)
    c.write(False)
    network.drain()
    assert not r.read()
    assert co.read()

    a.write(False)
    b.write(False)
    c.write(True)
    network.drain()
    assert r.read()
    assert not co.read()

    a.write(True)
    b.write(False)
    c.write(True)
    network.drain()
    assert not r.read()
    assert co.read()

    a.write(False)
    b.write(True)
    c.write(True)
    network.drain()
    assert not r.read()
    assert co.read()

    a.write(True)
    b.write(True)
    c.write(True)
    network.drain()
    assert r.read()
    assert co.read()