Esempio n. 1
0
        public void GraphIsBuildCorrectly()
        {
            /*  graph visual:
             *      ┌──>va1──>va2──>va3<<─┐
             *  v1──┼──>vc1─────────────┤
             *      └──>vb1──>vb2──>vb3<<─┘
             */

            string       correctPathName = "correctPath";
            var          graph           = new UnweightedGraph();
            Vertex <int> v1  = new Vertex <int>(1);
            Vertex <int> va1 = new Vertex <int>(2);
            Vertex <int> va2 = new Vertex <int>(3);
            Vertex <int> va3 = new Vertex <int>(4);
            Vertex <int> vb1 = new Vertex <int>(5);
            Vertex <int> vb2 = new Vertex <int>(6);
            Vertex <int> vb3 = new Vertex <int>(7);
            Vertex <int> vc1 = new Vertex <int>(8);

            graph.AddEdge(v1, va1, "name");
            graph.AddEdge(va1, va2, "name");
            graph.AddEdge(va2, va3, "name");
            graph.AddEdge(v1, vb1, "name");
            graph.AddEdge(vb1, vb2, "name");
            graph.AddEdge(vb2, vb3, "name");
            graph.AddEdge(v1, vc1, correctPathName);
            graph.AddEdge(vc1, va3, correctPathName);
            graph.AddEdge(vc1, vb3, "name");


            Assert.Equal(8, graph.Vertices.Count);
            Assert.Equal(9, graph.Edges.Count());

            var bfs = graph.BreathFirstIterator(vb2).ToList();

            Assert.Equal(2, bfs.Count);

            Vertex <int> vstart = new Vertex <int>(1);
            Vertex <int> vend   = new Vertex <int>(4);
            var          sp     = graph.ShortestPath(vstart, vend).ToList();

            Assert.Equal(2, sp.Count());

            // Assert.All(sp, e => Assert.True(e. == correctPathName));
            Assert.Equal(v1, sp[0].From);
            Assert.Equal(vc1, sp[0].To);
            Assert.Equal(vc1, sp[1].From);
            Assert.Equal(va3, sp[1].To);
        }
    public HyperloopTests(ITestOutputHelper output)
    {
        _output = output;

        var cities = new[]
        {
            "Boston", "NewYork", "Philadelphia", "Washington", "Miami", "Atlanta", "Detroit", "Chicago",
            "Dallas", "Huston", "Phoenix", "Riverside", "LosAngeles", "SanFrancisco", "Seattle"
        };

        _cityGraph = new UnweightedGraph <string>(cities);

        _cityGraph.AddEdge("Boston", "NewYork");
        _cityGraph.AddEdge("Boston", "Detroit");
        _cityGraph.AddEdge("NewYork", "Detroit");
        _cityGraph.AddEdge("NewYork", "Philadelphia");
        _cityGraph.AddEdge("Washington", "Philadelphia");
        _cityGraph.AddEdge("Washington", "Detroit");
        _cityGraph.AddEdge("Washington", "Miami");
        _cityGraph.AddEdge("Washington", "Atlanta");
        _cityGraph.AddEdge("Miami", "Atlanta");
        _cityGraph.AddEdge("Miami", "Huston");
        _cityGraph.AddEdge("Atlanta", "Chicago");
        _cityGraph.AddEdge("Atlanta", "Huston");
        _cityGraph.AddEdge("Atlanta", "Dallas");
        _cityGraph.AddEdge("Huston", "Dallas");
        _cityGraph.AddEdge("Huston", "Phoenix");
        _cityGraph.AddEdge("Dallas", "Phoenix");
        _cityGraph.AddEdge("Dallas", "Chicago");
        _cityGraph.AddEdge("Detroit", "Chicago");
        _cityGraph.AddEdge("Riverside", "Chicago");
        _cityGraph.AddEdge("Riverside", "Phoenix");
        _cityGraph.AddEdge("Riverside", "LosAngeles");
        _cityGraph.AddEdge("Riverside", "SanFrancisco");
        _cityGraph.AddEdge("Phoenix", "LosAngeles");
        _cityGraph.AddEdge("SanFrancisco", "LosAngeles");
        _cityGraph.AddEdge("SanFrancisco", "Seattle");
        _cityGraph.AddEdge("Chicago", "Seattle");

        _weightedCityGraph = new WeightedGraph <string>(cities);
        _weightedCityGraph.AddEdge("Boston", "NewYork", 190);
        _weightedCityGraph.AddEdge("Boston", "Detroit", 613);
        _weightedCityGraph.AddEdge("NewYork", "Detroit", 482);
        _weightedCityGraph.AddEdge("NewYork", "Philadelphia", 81);
        _weightedCityGraph.AddEdge("Washington", "Philadelphia", 123);
        _weightedCityGraph.AddEdge("Washington", "Detroit", 396);
        _weightedCityGraph.AddEdge("Washington", "Miami", 923);
        _weightedCityGraph.AddEdge("Washington", "Atlanta", 543);
        _weightedCityGraph.AddEdge("Miami", "Atlanta", 604);
        _weightedCityGraph.AddEdge("Miami", "Huston", 968);
        _weightedCityGraph.AddEdge("Atlanta", "Chicago", 588);
        _weightedCityGraph.AddEdge("Atlanta", "Huston", 702);
        _weightedCityGraph.AddEdge("Atlanta", "Dallas", 721);
        _weightedCityGraph.AddEdge("Huston", "Dallas", 225);
        _weightedCityGraph.AddEdge("Huston", "Phoenix", 1015);
        _weightedCityGraph.AddEdge("Dallas", "Phoenix", 887);
        _weightedCityGraph.AddEdge("Dallas", "Chicago", 805);
        _weightedCityGraph.AddEdge("Detroit", "Chicago", 238);
        _weightedCityGraph.AddEdge("Riverside", "Chicago", 1704);
        _weightedCityGraph.AddEdge("Riverside", "Phoenix", 307);
        _weightedCityGraph.AddEdge("Riverside", "LosAngeles", 50);
        _weightedCityGraph.AddEdge("Riverside", "SanFrancisco", 386);
        _weightedCityGraph.AddEdge("Phoenix", "LosAngeles", 357);
        _weightedCityGraph.AddEdge("SanFrancisco", "LosAngeles", 348);
        _weightedCityGraph.AddEdge("SanFrancisco", "Seattle", 678);
        _weightedCityGraph.AddEdge("Chicago", "Seattle", 1737);
    }