From d9a071d520ee63a8304a3eb417787c0fb576843e Mon Sep 17 00:00:00 2001 From: Hirmay Sandesara <56473003+Hirmay@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:13:31 +0530 Subject: [PATCH] added test cases for ValueError cases --- ..._generalized_uniform_superposition_gate.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/python/circuit/library/test_generalized_uniform_superposition_gate.py b/test/python/circuit/library/test_generalized_uniform_superposition_gate.py index 23354e5b547..8ae159cfc2e 100644 --- a/test/python/circuit/library/test_generalized_uniform_superposition_gate.py +++ b/test/python/circuit/library/test_generalized_uniform_superposition_gate.py @@ -28,7 +28,7 @@ class TestGeneralizedUniformSuperposition(QiskitTestCase): def test_generalized_uniform_superposition_gate(self): """Test Generalized Uniform Superposition Gate""" M_min = 3 - M_max = 130 + M_max = 80 for M in range(M_min, M_max): if (M & (M-1)) == 0: # If M is an integer power of 2 n = int(np.log2(M)) @@ -39,6 +39,24 @@ def test_generalized_uniform_superposition_gate(self): unitary_matrix = np.real(gate.to_unitary()) actual_sv = unitary_matrix[:,0] self.assertTrue(np.allclose(desired_sv, actual_sv)) + + def test_incompatible_M(self): + """Test error raised if M not valid""" + M_min = -2 + M_max = 2 + n = 1 + for M in range(M_min, M_max): + with self.assertRaises(ValueError): + Generalized_Uniform_Superposition_Gate(M, n) + def test_incompatible_int_M_and_qubit_args(self): + """Test error raised if number of qubits not compatible with integer state M (n >= log2(M) )""" + n_min = 1 + n_max = 5 + M = 50 + for n in range(n_min, n_max): + with self.assertRaises(ValueError): + Generalized_Uniform_Superposition_Gate(M, n) + if __name__ == "__main__": unittest.main()