forked from microsoft/QuantumKatas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.qs
66 lines (53 loc) · 2.24 KB
/
Tests.qs
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
62
63
64
65
66
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
//////////////////////////////////////////////////////////////////////
// This file contains testing harness for all tasks.
// You should not modify anything in this file.
//////////////////////////////////////////////////////////////////////
namespace Quantum.Kata.MultiQubitGates {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Arrays;
operation T1_CompoundGate_Test () : Unit {
AssertOperationsEqualReferenced(3, CompoundGate, CompoundGate_Reference);
}
operation AssertEqualOnZeroState (testImpl : (Qubit[] => Unit), refImpl : (Qubit[] => Unit is Adj)) : Unit {
using (qs = Qubit[2]) {
// apply operation that needs to be tested
testImpl(qs);
// apply adjoint reference operation
Adjoint refImpl(qs);
// assert that all qubits end up in |0⟩ state
AssertAllZero(qs);
}
}
operation T2_BellState_Test () : Unit {
AssertEqualOnZeroState(BellState, BellState_Reference);
}
operation T3_QubitSwap_Test () : Unit {
for (N in 2 .. 5) {
for (j in 0 .. N-2) {
for (k in j+1 .. N-1) {
AssertOperationsEqualReferenced(N, QubitSwap(_, j, k), QubitSwap_Reference(_, j, k));
}
}
}
}
operation T4_ControlledRotation_Test () : Unit {
for (i in 0 .. 20) {
let angle = IntAsDouble(i) / 10.0;
AssertOperationsEqualReferenced(2, ControlledRotation(_, angle), ControlledRotation_Reference(_,angle));
}
}
operation ArrayControlledOperationWrapper (op : ((Qubit[], Qubit) => Unit is Adj), qs : Qubit[]) : Unit is Adj {
op(Most(qs), Tail(qs));
}
operation T5_MultiControls_Test () : Unit {
for (i in 0 .. (2 ^ 4) - 1) {
let bits = IntAsBoolArray(i, 4);
AssertOperationsEqualReferenced(5, ArrayControlledOperationWrapper(MultiControls(_, _, bits), _), ArrayControlledOperationWrapper(MultiControls_Reference(_, _, bits), _));
}
}
}