2 Copyright 2020 Peter Rakyta, Ph.D. 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 8 http://www.apache.org/licenses/LICENSE-2.0 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see http://www.gnu.org/licenses/. 24 """Tests for the inheritance structure of the CH gate in the Squander package""" 26 @pytest.mark.parametrize(
"gate_class", [
45 Test that gates properly inherits from the base Gate class. 48 from squander
import Gate
49 exec(f
"from squander import {gate_class}")
52 gate_cls = eval(gate_class)
53 assert issubclass(gate_cls, Gate)
56 if hasattr(gate_cls,
"control_qbit"):
57 gate_ins = gate_cls(3, 0, 1)
59 gate_ins = gate_cls(3, 0)
60 assert isinstance(gate_ins, Gate)
62 @pytest.mark.parametrize(
"gate_class", [
81 Test that gate inherits methods from the base Gate class. 84 from squander
import Gate
85 exec(f
"from squander import {gate_class}")
89 base_methods = [name
for name, obj
in inspect.getmembers(base_gate)
90 if (callable(obj)
and not name.startswith(
'_'))]
92 gate_cls = eval(gate_class)
95 if hasattr(gate_cls,
"control_qbit"):
96 gate_ins = gate_cls(3, 0, 1)
98 gate_ins = gate_cls(3, 0)
101 for method_name
in base_methods:
102 assert hasattr(gate_ins, method_name), f
"{gate_class} is missing method {method_name}" 105 assert gate_ins.get_Target_Qbit() == 0
106 if hasattr(gate_cls,
"control_qbit"):
107 assert gate_ins.get_Control_Qbit() == 1
109 name = gate_ins.get_Name()
110 assert isinstance(name, str)
def test_gate_inheritance(self, gate_class)
def test_gate_methods(self, gate_class)
Base class for the representation of general gate operations.