def test_bitvector_equal_bitvector(place):
    value = 1 << place
    a = BitVector(value)
    b = BitVector(value)
    assert isinstance(a, BitVector)
    assert isinstance(b, BitVector)
    assert a == b and a is not b
def test_bitvector_greater_than_bitvector(value):

    test = BitVector(value)
    zero = BitVector()
    assert zero == 0
    assert test == value
    assert test > zero
def test_bitvector_greater_than_or_equal_scalar(value):

    test = BitVector(value)
    zero = BitVector()
    assert zero == 0
    assert test == value
    assert test >= zero
Exemple #4
0
def test_bitvector_sub_bitvector(place: int):

    expected = BitVector(1 << place)
    test = BitVector(1 << place)
    assert test == expected and test is not expected

    result = test - expected
    assert isinstance(result, BitVector)
    assert result == 0
Exemple #5
0
def test_bitvector_isub_bitvector(place: int):

    expected = BitVector(1 << place)
    test = BitVector(1 << place)
    assert test == expected and test is not expected

    test -= expected
    assert isinstance(test, BitVector)
    assert test == 0
Exemple #6
0
def test_bitvector_add_bitvector_mismatched_sizes(size_a, size_b):

    a = BitVector(1, size=size_a)
    b = BitVector(1, size=size_b)

    c = a + b

    assert isinstance(c, BitVector)
    assert len(c) == len(min(a, b, key=len))
    assert c == (2 & c.MAX)
def test_bitvector_floordiv_bitvector_mismatched_sizes(size_a, size_b):

    a = BitVector(1, size=size_a)
    b = BitVector(1, size=size_b)

    c = a // b

    assert isinstance(c, BitVector)
    assert len(c) == len(min(a, b, key=len))
    assert c == 1
Exemple #8
0
def test_bitvector_mul_bitvector_mismatched_sizes(size_a, size_b):

    a = BitVector(1, size=size_a)
    b = BitVector(1, size=size_b)

    c = a * b

    assert isinstance(c, BitVector)
    assert len(c) == len(min(a, b, key=len))
    assert c == 1 and c == a and c == b
def test_bitvector_floordiv_scalar(value: int, BV_0: BitVector):

    test = BV_0 // value
    assert test == 0

    test = BitVector(value) // value
    assert test == 1
def test_bitvector_not_equal_scalar(scalar, expected):

    b = BitVector()
    assert b == 0

    result = b != scalar
    assert result == expected
Exemple #11
0
def test_bitvector_repr():

    bv = BitVector()
    repr_value = repr(bv)

    assert "BitVector" in repr_value
    assert "128" in repr_value
Exemple #12
0
def test_bitvector_hex_property(given):

    bv = BitVector()
    hex_value = bv.hex

    assert hex_value.startswith("0x")
    assert int(hex_value, 16) == bv.value
Exemple #13
0
def test_bitvector_str(given):

    bv = BitVector(given)
    str_value = str(bv)

    assert str_value.startswith("0x")
    assert int(str_value, 16) == bv.value
Exemple #14
0
def test_bitvector_bin_property(given):

    bv = BitVector()
    bin_value = bv.bin

    assert bin_value.startswith("0b")
    assert int(bin_value, 2) == bv.value
def test_bitvector_ifloordiv_scalar(value: int, BV_0: BitVector):

    BV_0 //= value
    assert BV_0 == 0

    test = BitVector(value)
    test //= value
    assert test == 1
def test_bitvector_floordiv_bitvector(value: int, BV_0: BitVector,
                                      BV_1: BitVector):

    test = BitVector(value)

    result = test // BV_1

    assert result == test and result is not test
Exemple #17
0
def test_bitvector_rsub_scalar(place: int):

    expected = 1 << place
    test = BitVector(expected)
    assert test == expected and test is not expected

    result = expected - test
    assert isinstance(result, int)
    assert result == 0
def test_bitvector_bitwise_ixor(value: int, BV_0: BitVector):

    BV_0 ^= value
    assert BV_0 == value

    test = BitVector(value)
    test ^= value

    assert test == 0
def test_bitvector_bitwise_xor(value: int, BV_0: BitVector):

    assert BV_0 ^ value == value
    assert value ^ BV_0 == value

    test = BitVector(value)

    assert test ^ value == 0
    assert value ^ test == 0
def test_bitvector_bitwise_or(value: int, BV_0: BitVector):

    assert BV_0 | value == value
    assert value | BV_0 == value

    test = BitVector(value)

    assert test | value == value
    assert value | test == value
Exemple #21
0
def test_bitvector_imul_bitvector(value: int, BV_0: BitVector,
                                  BV_1: BitVector):

    test = BitVector(value)

    BV_0 *= test
    assert BV_0 == 0

    BV_1 *= test
    assert BV_1 == test and BV_1 is not test
Exemple #22
0
def test_bitvector_bytes_property(value):

    bv = BitVector(value)
    bv_bytes = bv.bytes

    test = int.from_bytes(bv_bytes, "big")

    assert isinstance(bv_bytes, bytes)
    assert len(bv_bytes) == len(bv) / 8
    assert test == bv
Exemple #23
0
def test_bitvector_iadd_bitvector(value: int, BV_0: BitVector,
                                  BV_1: BitVector):

    bv = BitVector(value)

    BV_0 += bv
    assert BV_0 == value

    BV_1 += bv
    assert BV_1 == value + 1
Exemple #24
0
def test_bitvector_mul_bitvector(value: int, BV_0: BitVector, BV_1: BitVector):

    expected = BitVector(value)

    result = BV_1 * expected
    assert isinstance(result, BitVector)
    assert result == expected and result is not expected

    result = BV_0 * expected
    assert isinstance(result, BitVector)
    assert result == 0
def test_bitvector_greater_than_scalar(value):

    test = BitVector(value)
    assert test == value
    assert test > 0
def test_bitvector_less_than_or_equal_bitvector(value):

    test = BitVector()
    bigger = BitVector(value)
    assert test == 0
    assert test <= bigger
def test_bitvector_rfloordiv_scalar(value: int, BV_0: BitVector,
                                    BV_1: BitVector):

    result = value // BitVector(value)
    assert isinstance(result, int)
    assert result == 1
Exemple #28
0
def BV_1() -> BitVector:
    return BitVector(1)
Exemple #29
0
def BV_0() -> BitVector:
    return BitVector(0)
def test_bitvector_ifloordiv_bitvector(value: int):

    test = BitVector(value)
    test //= value
    assert test == 1