change shor's test from programmatic to declarative
@@ -20,8 +20,7 @@ import unittest
from parameterized import parameterized
from qiskit import BasicAer
-from qiskit.aqua import QuantumInstance
-from qiskit.aqua.algorithms import Shor
+from qiskit.aqua import run_algorithm
from test.common import QiskitAquaTestCase
@@ -29,15 +28,24 @@ class TestShor(QiskitAquaTestCase):
"""test Shor's algorithm"""
@parameterized.expand([
- [15, 'qasm_simulator'],
+ [15, 'qasm_simulator', [3, 5]],
])
- def test_shor(self, N, simulator):
- self.log.debug("Testing Shor's algorithm")
- shor = Shor(N)
- backend = BasicAer.get_backend(simulator)
- quantum_instance = QuantumInstance(backend, shots=100)
- ret = shor.run(quantum_instance)
- self.assertListEqual(ret['factors'][0], [3, 5])
+ def test_shor(self, N, backend, factors):
+ params = {
+ 'problem': {
+ 'name': 'factoring',
+ },
+ 'algorithm': {
+ 'name': 'Shor',
+ 'N': N,
+ },
+ 'backend': {
+ 'shots': 1000,
+ },
+ }
+
+ result_dict = run_algorithm(params, backend=BasicAer.get_backend(backend))
+ self.assertListEqual(result_dict['factors'][0], factors)
if __name__ == '__main__':
