add ground-truth checking in bv test
@@ -35,11 +35,23 @@ class TestBernsteinVazirani(QiskitAquaTestCase):
'100': '1', '101': '0', '110': '1', '111': '0'}]
])
def test_bernsteinvazirani(self, bv_input):
+ nbits = math.log(len(bv_input), 2)
+ if math.ceil(nbits) != math.floor(nbits):
+ raise AquaError('Input not the right length')
+ nbits = int(nbits)
+
+ # compute the ground-truth classically
+ parameter = ""
+ for i in range(nbits):
+ bitstring = np.binary_repr(2**i, nbits)
+ bit = bv_input[bitstring]
+ parameter += bit
+
backend = get_aer_backend('qasm_simulator')
oracle = ESOPOracle(bv_input)
algorithm = BernsteinVazirani(oracle)
result = algorithm.run(backend)
- self.assertTrue(result['oracle_evaluation'])
+ self.assertEqual(result['result'], parameter)
if __name__ == '__main__':
