public void AllGoodTest() { ToffoliSimulator sim = new ToffoliSimulator(); QVoid res = sim.Execute <AllGood1, QVoid, QVoid>(QVoid.Instance); StackFrame[] stackFrames = sim.CallStack; Assert.Null(stackFrames); }
public void ErrorLogTest() { ToffoliSimulator sim = new ToffoliSimulator(); var logs = new List <string>(); sim.OnLog += (msg) => logs.Add(msg); try { QVoid res = sim.Execute <AlwaysFail4, QVoid, QVoid>(QVoid.Instance); } catch (ExecutionFailException) { Assert.Equal(7, logs.Count); Assert.StartsWith("Unhandled exception. Microsoft.Quantum.Simulation.Core.ExecutionFailException: Always fail", logs[0]); Assert.StartsWith(" ---> Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.AlwaysFail", logs[1]); Assert.StartsWith(" at Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.AlwaysFail1 on", logs[2]); Assert.StartsWith(" at Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.AlwaysFail2 on", logs[3]); Assert.StartsWith(" at Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.AlwaysFail3 on", logs[4]); Assert.StartsWith(" at Microsoft.Quantum.Simulation.Simulators.Tests.Circuits.AlwaysFail4 on", logs[5]); Assert.Equal("", logs[6]); } logs.Clear(); sim.EnableStackTracePrinting = false; try { QVoid res = sim.Execute <AlwaysFail4, QVoid, QVoid>(QVoid.Instance); } catch (ExecutionFailException) { Assert.Equal(2, logs.Count); Assert.StartsWith("Unhandled exception. Microsoft.Quantum.Simulation.Core.ExecutionFailException: Always fail", logs[0]); Assert.Equal("", logs[1]); } }
public void DivideByZeroTest() { ToffoliSimulator sim = new ToffoliSimulator(); try { sim.Execute <DivideBy0, QVoid, long>(QVoid.Instance); } catch (Exception) { StackFrame[] stackFrames = sim.CallStack; Assert.Single(stackFrames); Assert.Equal(namespacePrefix + "DivideBy0", stackFrames[0].Callable.FullName); } }