Example #1
0
        public static string AssertSimulate(IQSharpEngine engine, string snippetName, params string[] messages)
        {
            var simMagic = new SimulateMagic(engine.SymbolsResolver);
            var channel  = new MockChannel();
            var response = simMagic.Execute(snippetName, channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Ok, response.Status);
            CollectionAssert.AreEqual(messages.Select(ChannelWithNewLines.Format).ToArray(), channel.msgs.ToArray());

            return(response.Output?.ToString());
        }
Example #2
0
        public void CompileAndSimulate()
        {
            var engine   = Init();
            var simMagic = new SimulateMagic(engine.SymbolsResolver);
            var channel  = new MockChannel();

            // Try running without compiling it, fails:
            var response = simMagic.Execute("_snippet_.HelloQ", channel);

            PrintResult(response, channel);
            Assert.AreEqual(ExecuteStatus.Error, response.Status);
            Assert.AreEqual(0, channel.msgs.Count);
            Assert.AreEqual(1, channel.errors.Count);
            Assert.AreEqual(ChannelWithNewLines.Format($"Invalid operation name: _snippet_.HelloQ"), channel.errors[0]);

            // Compile it:
            AssertCompile(engine, SNIPPETS.HelloQ, "HelloQ");

            // Try running again:
            AssertSimulate(engine, "HelloQ", "Hello from quantum world!");
        }