Пример #1
0
 def test_bit_not_2bit(self):
     function = BoolFunction(examples.bit_not_2bit)
     self.assertEqual(function.signature_, [[type(BitVec(2)), 2]])
     for a in range(4):
         tmp = BitVec(2, a)
         result = examples.bit_not_2bit(tmp)
         self.assertEqual(result, ~tmp)
Пример #2
0
 def test_bool_not(self):
     function = BoolFunction(examples.bool_not)
     self.assertEqual(function.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))
Пример #3
0
 def test_id(self):
     function = BoolFunction(examples.identity)
     self.assertEqual(function.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'))
Пример #4
0
 def test_bit_and_2bit(self):
     function = BoolFunction(examples.bit_and_2bit)
     self.assertEqual(function.signature_, [[type(BitVec(2)), 2], 
                                            [type(BitVec(2)), 2]])
     for a in range(4):
         for b in range(4):
             result = examples.bit_and_2bit(BitVec(2, a), BitVec(2, b))
             tmp = BitVec(2, a) & BitVec(2, b)
             self.assertEqual(result, tmp)
Пример #5
0
 def test_bit_or(self):
     function = BoolFunction(examples.bit_or)
     self.assertEqual(function.signature_, [[type(BitVec(1)), 1], 
                                            [type(BitVec(1)), 1]])
     for a in range(2):
         for b in range(2):
             result = examples.bit_or(BitVec(1, a), BitVec(1, b))
             tmp = BitVec(1, a) | BitVec(1, b)
             self.assertEqual(result, tmp)
Пример #6
0
 def test_xor_str(self):
     function = BoolFunction("x ^ b")
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 1)
     self.assertEqual(str(truth_table[0]), '0110')
Пример #7
0
 def test_or(self):
     function = BoolFunction(examples.bool_or)
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 1)
     self.assertEqual(str(truth_table[0]), '1110')
Пример #8
0
 def test_and_str(self):
     function = BoolFunction("x & b")
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 1)
     self.assertEqual(str(truth_table[0]), '1000')
Пример #9
0
 def test_not_2bit(self):
     function = BoolFunction(examples.bit_not_2bit)
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 2)
     self.assertEqual(str(truth_table[0]), '0101')
     self.assertEqual(str(truth_table[1]), '0011')
Пример #10
0
 def test_constant_2bit(self):
     function = BoolFunction(examples.constant_2bit)
     result = function.simulate()
     self.assertEqual(result, [False, True])
Пример #11
0
 def test_id_2bit(self):
     function = BoolFunction(examples.identity_2bit)
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 2)
     self.assertEqual(str(truth_table[0]), '1010')
     self.assertEqual(str(truth_table[1]), '1100')
Пример #12
0
 def test_id(self):
     function = BoolFunction(examples.identity)
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 1)
     self.assertEqual(str(truth_table[0]), '10')
Пример #13
0
 def test_bit_not_2bit(self):
     function = BoolFunction(examples.bit_not_2bit)
     for a in range(4):
         tmp = BitVec(2, a)
         result = function.simulate(tmp)
         self.assertEqual(result, [not tmp[0], not tmp[1]])
Пример #14
0
 def test_bit_not(self):
     function = BoolFunction(examples.bit_not)
     result = function.simulate(BitVec(1, '0'))
     self.assertEqual(result, [True])
     result = function.simulate(BitVec(1, '1'))
     self.assertEqual(result, [False])
Пример #15
0
 def test_id_2bit(self):
     function = BoolFunction(examples.identity_2bit)
     for a in range(4):
         tmp = BitVec(2, a)
         result = function.simulate(tmp)
         self.assertEqual(result, [bool(tmp[0]), bool(tmp[1])])
Пример #16
0
 def test_id(self):
     function = BoolFunction(examples.identity)
     result = function.simulate(BitVec(1, '0'))
     self.assertEqual(result, [False])
     result = function.simulate(BitVec(1, '1'))
     self.assertEqual(result, [True])
Пример #17
0
 def test_not_str(self):
     function = BoolFunction("~x")
     truth_table = function.simulate_all()
     self.assertEqual(len(truth_table), 1)
     self.assertEqual(str(truth_table[0]), '01')
Пример #18
0
 def test_constant_3bit(self):
     function = BoolFunction(examples.constant_3bit)
     self.assertEqual(function.signature_, [])
     result = examples.constant_3bit()
     self.assertEqual(result, BitVec(3, '101'))