Пример #1
0
 def test_bit_not_2bit(self):
     function = BoolFunction(bit_not_2bit)
     assert function._parameters_signature == [(type(BitVec(2)), 2)]
     for a in range(4):
         tmp = BitVec(2, a)
         result = bit_not_2bit(tmp)
         assert result == ~tmp
Пример #2
0
def create_bv_operand_pairs():
    operand_pairs = list()
    for i in range(1, 12):
        left = randrange((1 << i), (1 << (i + 1)))
        right = randrange((1 << i), (1 << (i + 1)))
        operand_pairs.append((BitVec((1 << i), left), BitVec((1 << i), right)))
    return operand_pairs
Пример #3
0
 def test_bit_xor_2bit(self):
     function = BoolFunction(examples.bit_xor_2bit)
     for a in range(4):
         for b in range(4):
             result = function.simulate(BitVec(2, a), BitVec(2, b))
             tmp = BitVec(2, a) ^ BitVec(2, b)
             self.assertEqual(result, tmp)
Пример #4
0
 def test_bit_or(self):
     function = BoolFunction(examples.bit_or)
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) | BitVec(1, b)
             self.assertEqual(result, tmp)
Пример #5
0
 def test_bool_not(self):
     function = BoolFunction(examples.bool_not)
     self.assertEqual(function._parameters_signature, [(type(BitVec(1)), 1)])
     for a in range(2):
         tmp = BitVec(1, a)
         result = examples.bool_not(tmp)
         self.assertEqual(result, not bool(tmp))
Пример #6
0
 def test_identity(self):
     function = BoolFunction(examples.identity)
     self.assertEqual(function._parameters_signature, [(type(BitVec(1)), 1)])
     result = examples.identity(BitVec(1, '0'))
     self.assertEqual(result, BitVec(1, '0'))
     result = examples.identity(BitVec(1, '1'))
     self.assertEqual(result, BitVec(1, '1'))
Пример #7
0
 def test_bool_and(self):
     function = BoolFunction(bool_and)
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) and BitVec(1, b)
             assert result == tmp
Пример #8
0
 def test_identity(self):
     function = BoolFunction(identity)
     assert function._parameters_signature == [(type(BitVec(1)), 1)]
     result = identity(BitVec(1, "0"))
     assert result == BitVec(1, "0")
     result = identity(BitVec(1, "1"))
     assert result == BitVec(1, "1")
Пример #9
0
 def test_bit_or(self):
     function = BoolFunction(bit_or)
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) | BitVec(1, b)
             assert result == tmp
Пример #10
0
 def test_bool_not(self):
     function = BoolFunction(bool_not)
     assert function._parameters_signature == [(type(BitVec(1)), 1)]
     for a in range(2):
         tmp = BitVec(1, a)
         result = bool_not(tmp)
         assert result is not bool(tmp)
Пример #11
0
 def test_identity_2bit(self):
     function = BoolFunction(identity_2bit)
     assert function._parameters_signature == [(type(BitVec(2)), 2)]
     for a in range(4):
         tmp = BitVec(2, a)
         result = identity(tmp)
         assert result == tmp
Пример #12
0
 def test_bit_not_2bit(self):
     function = BoolFunction(examples.bit_not_2bit)
     self.assertEqual(function._parameters_signature, [(type(BitVec(2)), 2)])
     for a in range(4):
         tmp = BitVec(2, a)
         result = examples.bit_not_2bit(tmp)
         self.assertEqual(result, ~tmp)
Пример #13
0
 def test_bit_xor_2bit(self):
     function = BoolFunction(bit_xor_2bit)
     for a in range(4):
         for b in range(4):
             result = function.simulate(BitVec(2, a), BitVec(2, b))
             tmp = BitVec(2, a) ^ BitVec(2, b)
             assert result == tmp
Пример #14
0
    def test_one_bit_value(self):
        zero_str = BitVec(1, 0)
        self.assertEqual(zero_str._length, 1)
        self.assertEqual(zero_str._value, 0)

        one_str = BitVec(1, 1)
        self.assertEqual(one_str._length, 1)
        self.assertEqual(one_str._value, 1)
Пример #15
0
def test_one_bit_value():
    zero = BitVec(1, 0)
    assert zero._length == 1
    assert zero._value == 0

    one = BitVec(1, 1)
    assert one._length == 1
    assert one._value == 1
Пример #16
0
def test_one_bit_str():
    zero_str = BitVec(1, "0")
    assert zero_str._length == 1
    assert zero_str._value == 0

    one_str = BitVec(1, "1")
    assert one_str._length == 1
    assert one_str._value == 1
Пример #17
0
 def setup(self):
     self.left_ops = list()
     self.right_ops = list()
     for i in range(1, 12):
         left = randrange((1 << i), (1 << (i + 1)))
         self.left_ops.append(BitVec((1 << i), left))
         right = randrange((1 << i), (1 << (i + 1)))
         self.left_ops.append(BitVec((1 << i), right))
Пример #18
0
def test_n_bit_strings(create_string_bitvectors):
    for _, string in create_string_bitvectors:
        bv = BitVec(len(string), string)
        assert bv._length == len(string)
        assert bv._value == int(string, 2)

        bv = BitVec(string)
        assert bv._length == len(string)
        assert bv._value == int(string, 2)
Пример #19
0
    def test_n_bit_strings(self):
        self.setup_strings()
        for length, string in self.strings:
            bv = BitVec(length, string)
            self.assertEqual(bv._length, length)
            self.assertEqual(bv._value, int(string, 2))

            bv = BitVec(string)
            self.assertEqual(bv._length, len(string))
            self.assertEqual(bv._value, int(string, 2))
Пример #20
0
 def test_identity(self):
     function = BoolFunction.from_truth_table("10")
     assert function.num_inputs() == 1
     assert function.num_outputs() == 1
     assert function.num_input_bits() == 1
     assert function.num_output_bits() == 1
     result = function.simulate(BitVec(1, "0"))
     assert result == BitVec(1, "0")
     result = function.simulate(BitVec(1, "1"))
     assert result == BitVec(1, "1")
Пример #21
0
 def test_identity(self):
     function = BoolFunction.from_truth_table('10')
     self.assertEqual(function.num_inputs(), 1)
     self.assertEqual(function.num_outputs(), 1)
     self.assertEqual(function.num_input_bits(), 1)
     self.assertEqual(function.num_output_bits(), 1)
     result = function.simulate(BitVec(1, '0'))
     self.assertEqual(result, BitVec(1, '0'))
     result = function.simulate(BitVec(1, '1'))
     self.assertEqual(result, BitVec(1, '1'))
Пример #22
0
 def test_and(self):
     function = BoolFunction.from_truth_table('1000')
     self.assertEqual(function.num_inputs(), 2)
     self.assertEqual(function.num_outputs(), 1)
     self.assertEqual(function.num_input_bits(), 2)
     self.assertEqual(function.num_output_bits(), 1)
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) and BitVec(1, b)
             self.assertEqual(result, tmp)
Пример #23
0
def test_setslice(create_string_bitvectors):
    for bv, _ in create_string_bitvectors[3:]:
        string = str(bv)
        result = BitVec(bv._length, (1 << bv._length - 1) - 1)
        n = int(bv._length / 4)
        for i in range(0, len(string), n):
            part = string[i:i + n]
            result[len(string) - i:len(string) - (i + n)] = BitVec(
                len(part), part)
        assert result._length == bv._length
        assert result._value == bv._value
Пример #24
0
 def test_and(self):
     function = BoolFunction.from_truth_table("1000")
     assert function.num_inputs() == 2
     assert function.num_outputs() == 1
     assert function.num_input_bits() == 2
     assert function.num_output_bits() == 1
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) and BitVec(1, b)
             assert result == tmp
Пример #25
0
 def test_setslice(self):
     self.setup_strings()
     for bv in self.bvs[3:]:
         string = str(bv)
         result = BitVec(bv._length, (1 << bv._length - 1) - 1)
         n = int(bv._length / 4)
         for i in range(0, len(string), n):
             part = string[i:i + n]
             result[len(string) - i:len(string) - (i + n)] = BitVec(
                 len(part), part)
         self.assertEqual(result._length, bv._length)
         self.assertEqual(result._value, bv._value)
Пример #26
0
 def test_xor(self):
     function = BoolFunction(examples.bool_and)
     function = BoolFunction.from_truth_table('0110')
     self.assertEqual(function.num_inputs(), 2)
     self.assertEqual(function.num_outputs(), 1)
     self.assertEqual(function.num_input_bits(), 2)
     self.assertEqual(function.num_output_bits(), 1)
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) ^ BitVec(1, b)
             self.assertEqual(result, tmp)
Пример #27
0
 def test_identity(self):
     function = BoolFunction(examples.identity)
     function.simulate_all()
     self.assertEqual(function.num_inputs(), 1)
     self.assertEqual(function.num_outputs(), 1)
     self.assertEqual(function.num_input_bits(), 1)
     self.assertEqual(function.num_output_bits(), 1)
     self.assertEqual(str(function.truth_table(output_bit=0)), '10')
     
     result = function.simulate(BitVec(1, '0'))
     self.assertEqual(result, BitVec(1, '0'))
     result = function.simulate(BitVec(1, '1'))
     self.assertEqual(result, BitVec(1, '1'))
Пример #28
0
 def test_or(self):
     function = BoolFunction(bool_or)
     function.simulate_all()
     assert function.num_inputs() == 2
     assert function.num_outputs() == 1
     assert function.num_input_bits() == 2
     assert function.num_output_bits() == 1
     assert str(function.truth_table(output_bit=0)) == "1110"
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) or BitVec(1, b)
             assert result == tmp
Пример #29
0
    def test_identity(self):
        function = BoolFunction(identity)
        function.simulate_all()
        assert function.num_inputs() == 1
        assert function.num_outputs() == 1
        assert function.num_input_bits() == 1
        assert function.num_output_bits() == 1
        assert str(function.truth_table(output_bit=0)) == "10"

        result = function.simulate(BitVec(1, "0"))
        assert result == BitVec(1, "0")
        result = function.simulate(BitVec(1, "1"))
        assert result == BitVec(1, "1")
Пример #30
0
 def test_or(self):
     function = BoolFunction(examples.bool_or)
     function.simulate_all()
     self.assertEqual(function.num_inputs(), 2)
     self.assertEqual(function.num_outputs(), 1)
     self.assertEqual(function.num_input_bits(), 2)
     self.assertEqual(function.num_output_bits(), 1)
     self.assertEqual(str(function.truth_table(output_bit=0)), '1110')
     for a in range(2):
         for b in range(2):
             result = function.simulate(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) or BitVec(1, b)
             self.assertEqual(result, tmp)