コード例 #1
0
def test_split_gate(a, b):
    circ = common.split_gate('input', 4, 'a', 4, 'b')
    val = circ({
        'input': common.encode_int(4, a) + common.encode_int(4, b),
    })[0]
    assert common.decode_int(val['a']) == a
    assert common.decode_int(val['b']) == b
コード例 #2
0
def test_combine_gate(a, b):
    circ = common.combine_gate(4, 'a', 4, 'b', output='out')
    val = circ({
        'a': common.encode_int(4, a),
        'b': common.encode_int(4, b)
    })[0]['out']
    assert common.decode_int(val[:4]) == a
    assert common.decode_int(val[4:]) == b
コード例 #3
0
def test_subtraction(a, b):
    circ = common.subtract_gate(4, left='a', right='b', output='out')
    val = circ({
        'a': common.encode_int(4, a),
        'b': common.encode_int(4, b),
    })[0]['out']
    assert common.decode_int(val) == a - b
コード例 #4
0
def test_bitwise_or(a, b):
    circ = common.bitwise_or(4, left='a', right='b', output='out')
    val = circ({
        'a': common.encode_int(4, a),
        'b': common.encode_int(4, b),
    })[0]['out']
    assert common.decode_int(val) == a | b
コード例 #5
0
def test_dec(a):
    circ = common.dec_gate(4, input='a', output='out')
    assert circ.inputs == {'a'}
    assert len(circ.aig.inputs) == 4
    assert circ.outputs == {'out'}
    assert len(circ.aig.outputs) == 4
    val = circ({'a': common.encode_int(4, a)})[0]['out']
    assert common.decode_int(val) == a - 1
コード例 #6
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_unsigned_multiply(x, y):
    if x * y > 15:
        return
    multiplier = atom(4, 'a', signed=False) * atom(4, 'b', signed=False)
    assert len(multiplier.inputs) == 2
    x_atom, y_atom = atom(4, x, signed=False), atom(4, y, signed=False)
    res = multiplier(inputs={'a': x_atom(), 'b': y_atom()})
    assert common.decode_int(res, signed=False) == x * y
コード例 #7
0
def test_logical_right_shift(a, b):
    circ = common.logical_right_shift_gate(8, b, 'a', output='out')
    val = circ({
        'a': common.encode_int(8, a, signed=True),
    })[0]['out']
    val2 = common.decode_int(val)
    assert (val2 & (0xff >> b)) == ((a >> b) & (0xff >> b))
    if b != 0:
        assert val[-1] is False
コード例 #8
0
def test_seqcomp(a):
    circ1 = common.identity_gate(4, input='a', output='tmp')
    circ2 = common.identity_gate(4, input='tmp', output='out')
    circ3 = circ1 >> circ2
    assert circ3.inputs == circ1.inputs
    assert circ3.outputs == circ2.outputs

    val = circ3({
        'a': common.encode_int(4, a),
    })[0]['out']
    assert common.decode_int(val) == a
コード例 #9
0
def test_lookup(a):
    lookup = {0: 0, 1: 1, 2: 0, 3: -1}
    circ = common.lookup(mapping=lookup,
                         input='x',
                         output='out',
                         inlen=2,
                         outlen=4,
                         in_signed=False)

    val = circ({
        'x': common.encode_int(2, a, signed=False),
    })[0]['out']
    assert common.decode_int(val) == lookup[a]
コード例 #10
0
def test_abs(a):
    circ = common.abs_gate(8, 'a', output='out')
    val = circ({
        'a': common.encode_int(8, a, signed=True),
    })[0]['out']
    assert common.decode_int(val) == abs(a)
コード例 #11
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_add(a, b):
    expr = atom(4, a) + atom(4, b)
    assert common.decode_int(expr()) == a + b
コード例 #12
0
def test_arithmetic_right_shift(a, b):
    circ = common.arithmetic_right_shift_gate(8, b, 'a', output='out')
    val = circ({
        'a': common.encode_int(8, a, signed=True),
    })[0]['out']
    assert common.decode_int(val) == a >> b
コード例 #13
0
def test_source(int_value):
    var = common.source(wordlen=4, value=int_value, name='x')
    assert common.decode_int(var({})[0]['x']) == int_value
コード例 #14
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_sub(a, b):
    expr = atom(4, a) - atom(4, b)
    assert common.decode_int(expr()) == a - b
コード例 #15
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_srl_signed(a, b):
    expr = atom(4, a) >> b
    assert common.decode_int(expr()) == a >> b
コード例 #16
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_sll(a, b):
    wordlen = 4
    expr = atom(wordlen, a, signed=False) << b
    mask = (1 << wordlen) - 1
    assert bin(common.decode_int(expr(), signed=False)) == bin((a << b) & mask)
コード例 #17
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_abs(a):
    expr = abs(atom(4, a))
    assert common.decode_int(expr()) == abs(a)
コード例 #18
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_bitwise_invert(a):
    expr = ~atom(4, a)
    assert common.decode_int(expr()) == ~a
コード例 #19
0
def test_identity(a):
    circ = common.identity_gate(4, input='a', output='out')
    val = circ({'a': common.encode_int(4, a)})[0]['out']
    assert common.decode_int(val) == a
コード例 #20
0
def test_bitwise_negate(a):
    circ = common.bitwise_negate(4, input='a', output='out')
    val = circ({'a': common.encode_int(4, a)})[0]['out']
    assert common.decode_int(val) == ~a
コード例 #21
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_multiply(x, y):
    multiplier = atom(6, 'a') * atom(6, 'b')
    x_atom, y_atom = atom(6, x), atom(6, y)
    res = multiplier(inputs={'a': x_atom(), 'b': y_atom()})
    assert common.decode_int(res) == x * y
コード例 #22
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_abs_max_negative():
    expr = abs(atom(4, -8))
    assert common.decode_int(expr()) == -8  # undefined behavior
コード例 #23
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_ite(test, a, b):
    _test, _a, _b = atom(1, test, signed=False), atom(4, a), atom(4, b)
    expr = ite(_test, _a, _b)
    val = common.decode_int(expr())
    assert val == (a if test else b)
コード例 #24
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_neg(a):
    expr = -atom(4, a)
    assert common.decode_int(expr()) == -a
コード例 #25
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_bitwise_and2(a):
    expr = atom(4, a) & atom(4, a)
    assert common.decode_int(expr()) == a
コード例 #26
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_getitem(a):
    expr = atom(4, a)
    for i in range(4):
        assert common.decode_int(expr[i](), signed=False) == (a >> i) & 1
コード例 #27
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_srl_unsigned(a, b):
    expr = atom(4, a) >> b
    assert common.decode_int(expr(), signed=False) == a >> b
コード例 #28
0
ファイル: test_expr.py プロジェクト: MarkusRabe/py-aiger-bv
def test_expr_bitwise_xor(a, b):
    expr = atom(4, a) ^ atom(4, b)
    assert common.decode_int(expr()) == a ^ b
コード例 #29
0
def test_reverse(a):
    circ = common.reverse_gate(4, input='a', output='out')
    val = circ({'a': common.encode_int(4, a)})[0]['out']
    assert common.decode_int(val[::-1]) == a
コード例 #30
0
ファイル: test_expr.py プロジェクト: mvcisback/py-aiger-bv
def test_encoded_add():
    adder = uatom(3, 'x') + 2
    res = adder(inputs={'x': 0b000})
    assert common.decode_int(res) == 2