-
Notifications
You must be signed in to change notification settings - Fork 66
/
test.py
61 lines (44 loc) · 1.45 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
import QuSim
###########################################
# Cases #
###########################################
# Pauli-X Gate
X = QuSim.QuantumRegister(1)
X.applyGate('X', 1)
# Multiple qubits
Multi = QuSim.QuantumRegister(5)
Multi.applyGate('X', 4)
# CNOT Gates
CNOT1 = QuSim.QuantumRegister(10)
CNOT1.applyGate('CNOT', 3, 7)
CNOT2 = QuSim.QuantumRegister(10)
CNOT2.applyGate('X', 3)
CNOT2.applyGate('CNOT', 3, 7)
CNOT3 = QuSim.QuantumRegister(9)
CNOT3.applyGate('X', 3)
CNOT3.applyGate('X', 7)
CNOT3.applyGate('CNOT', 3, 7)
###########################################
# Tests #
###########################################
class QuSimTests(unittest.TestCase):
def testXGate(self):
self.assertEqual(X.measure(), '1')
def testMultipleQubits(self):
self.assertEqual(Multi.measure(), '00010')
def testCNOT(self):
self.assertEqual(CNOT1.measure(), '0000000000')
self.assertEqual(CNOT2.measure(), '0010001000')
self.assertEqual(CNOT3.measure(), '001000000')
def testRemeasure(self):
self.assertEqual(CNOT1.measure(), '0000000000')
self.assertEqual(CNOT2.measure(), '0010001000')
self.assertEqual(CNOT3.measure(), '001000000')
def testReapplyGate(self):
with self.assertRaises(ValueError):
CNOT1.applyGate('X', 4)
def main():
unittest.main()
if __name__ == '__main__':
main()