예제 #1
0
        public void AllocateQubit2Test()
        {
            using (var sim = new QuantumSimulator())
            {
                try
                {
                    IgnorableAssert.Disable();
                    QVoid res = sim.Execute <AllocateQubit2, QVoid, QVoid>(QVoid.Instance);
                }
                catch (ExecutionFailException)
                {
                    StackFrame[] stackFrames = sim.CallStack;

                    // The following assumes that Assert is on Q# stack.
                    Assert.Equal(2, stackFrames.Length);

                    Assert.Equal("Microsoft.Quantum.Intrinsic.Assert", stackFrames[0].Callable.FullName);
                    Assert.Equal(namespacePrefix + "AllocateQubit2", stackFrames[1].Callable.FullName);

                    Assert.Equal(OperationFunctor.Body, stackFrames[0].Callable.Variant);
                    Assert.Equal(OperationFunctor.Body, stackFrames[1].Callable.Variant);

                    Assert.Equal(94, stackFrames[1].FailedLineNumber);
                }
                finally
                {
                    IgnorableAssert.Enable();
                }
            }
        }
예제 #2
0
        public void AllocateQubit2Test()
        {
            using var sim = new QuantumSimulator();
            try
            {
                IgnorableAssert.Disable();
                QVoid res = sim.Execute <AllocateQubit2, QVoid, QVoid>(QVoid.Instance);
            }
            catch (ExecutionFailException)
            {
                var stackFrames = sim.CallStack;

                // Make sure that the call stack isn't null before proceeding.
                Assert.NotNull(stackFrames);

                // The following assumes that Assert is on Q# stack.
                Assert.Equal(2, stackFrames !.Length);

                Assert.Equal("Microsoft.Quantum.Diagnostics.AssertMeasurement", stackFrames[0].Callable.FullName);
                Assert.Equal(namespacePrefix + "AllocateQubit2", stackFrames[1].Callable.FullName);

                Assert.Equal(OperationFunctor.Body, stackFrames[0].Callable.Variant);
                Assert.Equal(OperationFunctor.Body, stackFrames[1].Callable.Variant);

                Assert.Equal(94, stackFrames[1].FailedLineNumber);
            }
            finally
            {
                IgnorableAssert.Enable();
            }
        }
예제 #3
0
        public void SimpleRange()
        {
            Helper.RunWithMultipleSimulators((s) =>
            {
                IgnorableAssert.Disable();
                try
                {
                    //We have to call the method in the same thread for IgnorableAssert.Disable() to work
                    s.Get <SimpleRangeTest>().Apply(QVoid.Instance);
                }
                finally
                {
                    IgnorableAssert.Enable();
                }

                var tracer = s.GetTracer <long>();

                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (0L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (1L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (2L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (3L)));
                Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (4L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (5L)));
                Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (6L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (7L)));
                Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (8L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (9L)));
                Assert.Equal(1, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (10L)));
                Assert.Equal(0, tracer.Log.GetNumberOfCalls(OperationFunctor.Body, (11L)));
            });
        }