Esempio n. 1
0
        public void QSharpTypeTests()
        {
            Helper.RunWithMultipleSimulators((qsim) =>
            {
                var _ = AbstractCallable._;

                var x      = qsim.Get <Intrinsic.X>();
                var q2     = new FreeQubit(2) as Qubit;
                var Q      = new Q(q2);
                var Qs     = new QArray <Qubit>(q2);
                var qs     = new Qs(Qs);
                var udtOp  = new U3(x);
                var udtQ   = new Q(q2);
                var t4     = new T4((3L, (1.1, false, Result.One)));
                var t5     = new T5((Pauli.PauliX, Qs, qs, Q));
                var plain  = qsim.Get <BPlain1>();
                var adj    = qsim.Get <BAdj1>();
                var ctrl   = qsim.Get <BCtrl1>();
                var mapper = qsim.Get <Circuits.ClosedType.Map>();

                Assert.Equal("()", typeof(QVoid).QSharpType());
                Assert.Equal("_", _.GetType().QSharpType());
                Assert.Equal("U3", udtOp.GetType().QSharpType());
                Assert.Equal("Qubit => () : Adjoint, Controlled", udtOp.Data.GetType().QSharpType());
                Assert.Equal("Qubit", q2.GetType().QSharpType());
                Assert.Equal("Q", udtQ.GetType().QSharpType());
                Assert.Equal("Qubit", udtQ.Data.GetType().QSharpType());
                Assert.Equal("T4", t4.GetType().QSharpType());
                Assert.Equal("(Int,(Double,Boolean,Result))", t4.Data.GetType().QSharpType());
                Assert.Equal("T5", t5.GetType().QSharpType());
                Assert.Equal("(Pauli,Qubit[],Qs,Q)", t5.Data.GetType().QSharpType());
                Assert.Equal("Qubit => () : Adjoint, Controlled", x.GetType().QSharpType());
                Assert.Equal("Qubit => () : Adjoint, Controlled", x.Adjoint.GetType().QSharpType());
                Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.GetType().QSharpType());
                Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.Adjoint.GetType().QSharpType());
                Assert.Equal("(Int,Qubit,Callable) => ()", plain.GetType().QSharpType());
                Assert.Equal("(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.GetType().QSharpType());
                Assert.Equal("(Int,Qs,Controllable) => () : Controlled", ctrl.GetType().QSharpType());
                Assert.Equal("(Callable,Result[]) => String[]", mapper.GetType().QSharpType());
            });
        }