Пример #1
0
 public void ConsoleMenu_WhenExecuted_ShouldDisplayHeaderText()
 {
     string header_text = "This is the test header text 123455543321";
     TestConsole console = new TestConsole();
     // Pass a 0 to make the execution stop
     console.AddInputLine("0");
     ConsoleMenu menu = new ConsoleMenu(header_text);
     menu.Execute(console);
     Assert.IsTrue(console.OutputContains(header_text));
 }
Пример #2
0
 public CommandLineOptionsTests(ITestOutputHelper output)
 {
     _console = new();
 }
 public SuggestionShellScriptHandlerTest()
 {
     _parser  = new SuggestionDispatcher(new TestSuggestionRegistration()).Parser;
     _console = new TestConsole();
 }
Пример #4
0
 public TestHost(IDependencyContainer container, ILogger logger)
 {
     this.logger = logger;
     Console     = new TestConsole(container);
 }
 /// <summary>
 /// Turns on emitting of VT/ANSI sequences.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <returns>The same instance so that multiple calls can be chained.</returns>
 public static TestConsole EmitAnsiSequences(this TestConsole console)
 {
     console.SetCursor(null);
     console.EmitAnsiSequences = true;
     return(console);
 }
 /// <summary>
 /// Sets the console width.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <param name="width">The console width.</param>
 /// <returns>The same instance so that multiple calls can be chained.</returns>
 public static TestConsole Width(this TestConsole console, int width)
 {
     console.Profile.Width = width;
     return(console);
 }
Пример #7
0
 public CleanupServiceTests(ITestOutputHelper outputHelper)
 {
     _console = new TestConsole(outputHelper);
 }
 /// <summary>
 /// Sets the console's color system.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <param name="colors">The color system to use.</param>
 /// <returns>The same instance so that multiple calls can be chained.</returns>
 public static TestConsole Colors(this TestConsole console, ColorSystem colors)
 {
     console.Profile.Capabilities.ColorSystem = colors;
     return(console);
 }
 public ContentViewGenericTests()
 {
     _console  = new TestConsole();
     _renderer = new ConsoleRenderer(_console);
 }
Пример #10
0
 private string CleanUp(TestConsole capturingConsole) =>
 capturingConsole.Out
 .ToString()
 .Replace(_rootCommandName + " ", "");
Пример #11
0
 public CommandLineOptionsTests(ITestOutputHelper output)
 {
     _console      = new();
     _testReporter = new(output);
 }
Пример #12
0
        public void Scenario()
        {
            AdjacencyGraph <string, Edge <string> > graph = new AdjacencyGraph <string, Edge <string> >(true);

            // Add some vertices to the graph
            graph.AddVertex("A");
            graph.AddVertex("B");
            graph.AddVertex("C");
            graph.AddVertex("D");
            graph.AddVertex("E");
            graph.AddVertex("F");
            graph.AddVertex("G");
            graph.AddVertex("H");
            graph.AddVertex("I");
            graph.AddVertex("J");

            // Create the edges
            Edge <string> a_b = new Edge <string>("A", "B");
            Edge <string> a_d = new Edge <string>("A", "D");
            Edge <string> b_a = new Edge <string>("B", "A");
            Edge <string> b_c = new Edge <string>("B", "C");
            Edge <string> b_e = new Edge <string>("B", "E");
            Edge <string> c_b = new Edge <string>("C", "B");
            Edge <string> c_f = new Edge <string>("C", "F");
            Edge <string> c_j = new Edge <string>("C", "J");
            Edge <string> d_e = new Edge <string>("D", "E");
            Edge <string> d_g = new Edge <string>("D", "G");
            Edge <string> e_d = new Edge <string>("E", "D");
            Edge <string> e_f = new Edge <string>("E", "F");
            Edge <string> e_h = new Edge <string>("E", "H");
            Edge <string> f_i = new Edge <string>("F", "I");
            Edge <string> f_j = new Edge <string>("F", "J");
            Edge <string> g_d = new Edge <string>("G", "D");
            Edge <string> g_h = new Edge <string>("G", "H");
            Edge <string> h_g = new Edge <string>("H", "G");
            Edge <string> h_i = new Edge <string>("H", "I");
            Edge <string> i_f = new Edge <string>("I", "F");
            Edge <string> i_j = new Edge <string>("I", "J");
            Edge <string> i_h = new Edge <string>("I", "H");
            Edge <string> j_f = new Edge <string>("J", "F");

            // Add the edges
            graph.AddEdge(a_b);
            graph.AddEdge(a_d);
            graph.AddEdge(b_a);
            graph.AddEdge(b_c);
            graph.AddEdge(b_e);
            graph.AddEdge(c_b);
            graph.AddEdge(c_f);
            graph.AddEdge(c_j);
            graph.AddEdge(d_e);
            graph.AddEdge(d_g);
            graph.AddEdge(e_d);
            graph.AddEdge(e_f);
            graph.AddEdge(e_h);
            graph.AddEdge(f_i);
            graph.AddEdge(f_j);
            graph.AddEdge(g_d);
            graph.AddEdge(g_h);
            graph.AddEdge(h_g);
            graph.AddEdge(h_i);
            graph.AddEdge(i_f);
            graph.AddEdge(i_h);
            graph.AddEdge(i_j);
            graph.AddEdge(j_f);

            // Define some weights to the edges
            Dictionary <Edge <string>, double> edgeCost = new Dictionary <Edge <string>, double>(graph.EdgeCount);

            edgeCost.Add(a_b, 4);
            edgeCost.Add(a_d, 1);
            edgeCost.Add(b_a, 74);
            edgeCost.Add(b_c, 2);
            edgeCost.Add(b_e, 12);
            edgeCost.Add(c_b, 12);
            edgeCost.Add(c_f, 74);
            edgeCost.Add(c_j, 12);
            edgeCost.Add(d_e, 32);
            edgeCost.Add(d_g, 22);
            edgeCost.Add(e_d, 66);
            edgeCost.Add(e_f, 76);
            edgeCost.Add(e_h, 33);
            edgeCost.Add(f_i, 11);
            edgeCost.Add(f_j, 21);
            edgeCost.Add(g_d, 12);
            edgeCost.Add(g_h, 10);
            edgeCost.Add(h_g, 2);
            edgeCost.Add(h_i, 72);
            edgeCost.Add(i_f, 31);
            edgeCost.Add(i_h, 18);
            edgeCost.Add(i_j, 7);
            edgeCost.Add(j_f, 8);

            // We want to use Dijkstra on this graph
            var dijkstra = new DijkstraShortestPathAlgorithm <string, Edge <string> >(graph, e => edgeCost[e]);

            // Attach a Vertex Predecessor Recorder Observer to give us the paths
            var predecessorObserver = new VertexPredecessorRecorderObserver <string, Edge <string> >();

            using (predecessorObserver.Attach(dijkstra))
            {
                // Run the algorithm with A set to be the source
                dijkstra.Compute("A");
            }

            foreach (KeyValuePair <string, Edge <string> > kvp in predecessorObserver.VertexPredecessors)
            {
                TestConsole.WriteLine("If you want to get to {0} you have to enter through the in edge {1}", kvp.Key, kvp.Value);
            }

            foreach (string v in graph.Vertices)
            {
                double distance =
                    AlgorithmExtensions.ComputePredecessorCost(
                        predecessorObserver.VertexPredecessors,
                        edgeCost, v);
                TestConsole.WriteLine("A -> {0}: {1}", v, distance);
            }
        }
Пример #13
0
 public IConsoleExtensionTests(ITestOutputHelper output)
 {
     _output  = output;
     _console = new TestConsole(_output);
 }
Пример #14
0
        public void NotEnoughPaths()
        {
            int ii    = 0;
            var graph = new BidirectionalGraph <int, TaggedEdge <int, int> >();

            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(493, 495, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(495, 493, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(497, 499, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(499, 497, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(499, 501, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(501, 499, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(501, 503, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(503, 501, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(503, 505, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(505, 503, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(505, 507, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(507, 505, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(507, 509, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(509, 507, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(509, 511, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(511, 509, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2747, 2749, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2749, 2747, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2749, 2751, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2751, 2749, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2751, 2753, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2753, 2751, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2753, 2755, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2755, 2753, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2755, 2757, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2757, 2755, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2757, 2759, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2759, 2757, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2763, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2763, 2761, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2765, 2767, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2767, 2765, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2763, 2765, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2765, 2763, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(654, 978, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(978, 654, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(978, 1302, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1302, 978, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1302, 1626, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1626, 1302, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1626, 1950, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1950, 1626, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1950, 2274, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2274, 1950, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2274, 2598, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2598, 2274, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(513, 676, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(676, 513, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2767, 2608, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2608, 2767, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2287, 2608, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2608, 2287, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(676, 999, ii++));;
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(999, 676, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1321, 1643, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1643, 1321, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1643, 1965, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1965, 1643, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1965, 2287, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2287, 1965, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(999, 1321, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1321, 999, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2745, 2747, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2747, 2745, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(650, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 650, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(650, 970, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(970, 650, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2258, 2582, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2582, 2258, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(970, 1291, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1291, 970, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1935, 2258, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2258, 1935, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1291, 1613, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1613, 1291, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1613, 1935, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(1935, 1613, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2582, 2745, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2745, 2582, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(495, 497, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(497, 495, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(511, 513, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(513, 511, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 493, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(493, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(491, 654, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(654, 491, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2598, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2598, 2761, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2761, 2759, ii++));
            graph.AddVerticesAndEdge(new TaggedEdge <int, int>(2759, 2761, ii++));

            var test1 = new HoffmanPavleyRankedShortestPathAlgorithm <int, TaggedEdge <int, int> >(graph, e => 1.0);

            test1.ShortestPathCount = 5;
            test1.Compute(1626, 1965);
            Assert.AreEqual(4, test1.ComputedShortestPathCount);
            TestConsole.WriteLine("path: {0}", test1.ComputedShortestPathCount);
            foreach (var path in test1.ComputedShortestPaths)
            {
                foreach (var edge in path)
                {
                    Console.Write(edge + ":");
                }
                TestConsole.WriteLine();
            }
        }
 /// <summary>
 /// Sets whether or not ANSI is supported.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <param name="enable">Whether or not VT/ANSI control codes are supported.</param>
 /// <returns>The same instance so that multiple calls can be chained.</returns>
 public static TestConsole SupportsAnsi(this TestConsole console, bool enable)
 {
     console.Profile.Capabilities.Ansi = enable;
     return(console);
 }
Пример #16
0
 public ProgramTests(ITestOutputHelper output)
 {
     _tempDir = new TemporaryDirectory();
     _console = new TestConsole(output);
 }
 /// <summary>
 /// Makes the console interactive.
 /// </summary>
 /// <param name="console">The console.</param>
 /// <returns>The same instance so that multiple calls can be chained.</returns>
 public static TestConsole Interactive(this TestConsole console)
 {
     console.Profile.Capabilities.Interactive = true;
     return(console);
 }
Пример #18
0
 public void ConsoleMenu_WhenExecuted_AndSentZero_ShouldStopExecuting()
 {
     TestConsole console = new TestConsole();
     console.AddInputLine("0");
     ConsoleMenu menu = new ConsoleMenu("");
     menu.Execute(console);
 }
Пример #19
0
 public MinorTests()
 {
     _console = new TestConsole();
 }