Beispiel #1
0
        public void Test_ToChar()
        {
            String s1  = "100";
            String s2  = "10021";
            String s3  = "201341";
            String s4  = "201442";
            String s5  = "3015";
            String s6  = "400";
            String s7  = "40021";
            String s8  = "501341";
            String s9  = "501442";
            String s10 = "6015";
            String s11 = "700";
            String s12 = "70021";
            String s13 = "801341";
            String s14 = "801442";
            String s15 = "9015";
            String s16 = "9016";

            String[] sorted = new String[16] {
                s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16
            };
            String[] unsorted = new String[16] {
                s8, s5, s9, s15, s3, s4, s13, s1, s11, s2, s7, s16, s10, s12, s14, s6
            };

            MostSignificantDigitFirstSort.Sort(unsorted, Alphabet.Decimal);

            AssertUtilities.Sequence(sorted, unsorted);
        }
        public void Test_ToChar()
        {
            String s1  = "100";
            String s2  = "10021";
            String s3  = "201341";
            String s4  = "201442";
            String s5  = "3015";
            String s6  = "400";
            String s7  = "40021";
            String s8  = "501341";
            String s9  = "501442";
            String s10 = "6015";
            String s11 = "700";
            String s12 = "70021";
            String s13 = "801341";
            String s14 = "801442";
            String s15 = "9015";
            String s16 = "9016";

            String[] sorted = new String[16] {
                s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16
            };
            String[] unsorted = new String[16] {
                s8, s5, s9, s15, s3, s4, s13, s1, s11, s2, s7, s16, s10, s12, s14, s6
            };

            QuickSort3WaySort.Sort(unsorted);

            AssertUtilities.Sequence(sorted, unsorted);
        }
        public void Test_ToIndices()
        {
            Alphabet alphabet = Alphabet.Decimal;

            AssertUtilities.Sequence(new Int32[3] {
                7, 8, 9
            }, alphabet.ToIndices("789"));
        }
        public void Test_Post()
        {
            DepthFirstOrder order = new DepthFirstOrder(this.CreateDigraph());

            AssertUtilities.Sequence(new Int32[6] {
                5, 4, 3, 2, 1, 0
            }, order.Post());
        }
        public void Test_Path_Iteration()
        {
            BreadthFirstSearch bfs = this.CreateBFS();

            AssertUtilities.Sequence(new Int32[2] {
                5, 3
            }, bfs.PathFromSourceTo(3));
        }
        public void Test_ReversePost()
        {
            DepthFirstOrder order = new DepthFirstOrder(this.CreateDigraph());

            AssertUtilities.Sequence(new Int32[6] {
                0, 1, 2, 3, 4, 5
            }, order.ReversePost());
        }
        public void Test_Pre()
        {
            DepthFirstOrder order = new DepthFirstOrder(this.CreateDigraph());

            AssertUtilities.Sequence(new Int32[6] {
                0, 3, 4, 5, 1, 2
            }, order.Pre());
        }
        public void Test_ToChars()
        {
            Alphabet alphabet = Alphabet.Decimal;

            AssertUtilities.Sequence(new Char[3] {
                '7', '8', '9'
            }, alphabet.ToChars(new Int32[3] {
                7, 8, 9
            }));
        }
Beispiel #9
0
        public void Test_PathTo()
        {
            AcyclicLongestPath alp = new AcyclicLongestPath(this.CreateDigraph(), 0);

            AssertUtilities.Sequence(new Edge[2]
            {
                new Edge(0, 1, .5),
                new Edge(1, 4, 1.2),
            },
                                     alp.PathTo(4));
        }
Beispiel #10
0
        public void Test_Iteration()
        {
            Graph graph = new Graph(3);

            graph.AddEdge(0, 1);
            graph.AddEdge(1, 2);
            graph.AddEdge(2, 0);

            AssertUtilities.Sequence(new Int32[2] {
                2, 1
            }, graph.GetAdjacentVertices(0));
        }
Beispiel #11
0
        public void Test_GetKeysWithPrefix()
        {
            TernarySearchTrie trie = this.CreateTrie();

            AssertUtilities.Sequence(new String[3]
            {
                "1010",
                "1011",
                "1012"
            },
                                     trie.GetKeysWithPrefix("101"));
        }
Beispiel #12
0
        public void Test_GetKeysThatMatch()
        {
            TernarySearchTrie trie = this.CreateTrie();

            AssertUtilities.Sequence(new String[3]
            {
                "1110",
                "1111",
                "1112"
            },
                                     trie.GetKeysThatMatch("111."));
        }
        public void Test_PathTo()
        {
            DijkstraShortestPathAlgorithm alg = new DijkstraShortestPathAlgorithm(this.CreateDigraph(), 0);

            AssertUtilities.Sequence(new Edge[4]
            {
                new Edge(0, 1, .5),
                new Edge(1, 5, .3),
                new Edge(5, 6, .5),
                new Edge(6, 4, .1)
            },
                                     alg.PathTo(4));
        }
Beispiel #14
0
        public void Test_Iteration()
        {
            EdgeWeightedDigraph graph = new EdgeWeightedDigraph(3);

            Edge e0 = new Edge(0, 1, 0.5);

            graph.AddEdge(e0);
            graph.AddEdge(new Edge(1, 2, 0.2));
            graph.AddEdge(new Edge(2, 0, 0.1));

            AssertUtilities.Sequence(new Edge[1] {
                e0
            }, graph.GetAdjacentVertices(0));
        }
        public void Test_Reverse()
        {
            Digraph graph = new Digraph(3);

            graph.AddEdge(0, 1);
            graph.AddEdge(1, 2);
            graph.AddEdge(2, 0);

            graph = graph.Reverse();

            AssertUtilities.Sequence(new Int32[1] {
                0
            }, graph.GetAdjacentVertices(1));
        }
        public void Test_Order()
        {
            Digraph graph = new Digraph(4);

            graph.AddEdge(0, 1);
            graph.AddEdge(0, 2);
            graph.AddEdge(2, 3);

            TopologicalChecker checker = TopologicalChecker.Create(graph);

            AssertUtilities.Sequence(new Int32[4] {
                0, 1, 2, 3
            }, checker.Order);
        }
Beispiel #17
0
        public void Test_GetCycle()
        {
            Digraph graph = new Digraph(3);

            graph.AddEdge(0, 1);
            graph.AddEdge(1, 2);
            graph.AddEdge(2, 0);

            CycleChecker checker = CycleChecker.Create(graph);

            AssertUtilities.Sequence(new Int32[4] {
                2, 0, 1, 2
            }, checker.GetCycle());
        }
        public void Test_GetEdges_Iteration()
        {
            EdgeWeightedGraph   graph = this.CreateGraph();
            KruskalMSTAlgorithm msta  = KruskalMSTAlgorithm.Create(graph);

            AssertUtilities.Sequence(new Edge[4]
            {
                new Edge(0, 4, .2),
                new Edge(1, 2, .3),
                new Edge(0, 1, .5),
                new Edge(1, 3, .6)
            },
                                     msta.GetEdges());
        }
        public void Test_GetEdges_Iteration()
        {
            EdgeWeightedGraph graph = new EdgeWeightedGraph(3);

            Edge e0 = new Edge(0, 1, .5);
            Edge e1 = new Edge(1, 2, 0.2);
            Edge e2 = new Edge(2, 0, 0.1);

            graph.AddEdge(e0);
            graph.AddEdge(e1);
            graph.AddEdge(e2);

            AssertUtilities.Sequence(new Edge[3] {
                e1, e0, e2
            }, graph.GetEdges());
        }
        public void Test_GetCycle()
        {
            EdgeWeightedDigraph graph = new EdgeWeightedDigraph(3);

            Edge e0 = new Edge(0, 1, .3);
            Edge e1 = new Edge(1, 2, .8);
            Edge e2 = new Edge(2, 0, .5);

            graph.AddEdge(e0);
            graph.AddEdge(e1);
            graph.AddEdge(e2);

            EdgeWeightedCycleChecker checker = EdgeWeightedCycleChecker.Create(graph);

            AssertUtilities.Sequence(new Edge[] { e0, e1, e2 }, checker.GetCycle());
        }
Beispiel #21
0
        public void Test_GetKeys()
        {
            TernarySearchTrie trie = this.CreateTrie();

            AssertUtilities.Sequence(new String[9]
            {
                "1000",
                "1001",
                "1002",
                "1010",
                "1011",
                "1012",
                "1110",
                "1111",
                "1112"
            },
                                     trie.GetKeys());
        }
Beispiel #22
0
        public void Test_ToChar()
        {
            String s1 = "1001";
            String s2 = "1002";
            String s3 = "2013";
            String s4 = "2014";
            String s5 = "3015";

            String[] sorted = new String[5] {
                s1, s2, s3, s4, s5
            };
            String[] unsorted = new String[5] {
                s5, s3, s4, s1, s2
            };

            LeastSignificantDigitFirstSort.Sort(unsorted, 4, Alphabet.Decimal);

            AssertUtilities.Sequence(sorted, unsorted);
        }
        public void Test()
        {
            KeyValuePair <Int32, Double> kv1 = new KeyValuePair <Int32, Double>(1, 0.5);
            KeyValuePair <Int32, Double> kv2 = new KeyValuePair <Int32, Double>(1, 0.8);
            KeyValuePair <Int32, Double> kv3 = new KeyValuePair <Int32, Double>(2, 1.8);
            KeyValuePair <Int32, Double> kv4 = new KeyValuePair <Int32, Double>(2, 1.2);
            KeyValuePair <Int32, Double> kv5 = new KeyValuePair <Int32, Double>(3, 2.2);
            KeyValuePair <Int32, Double> kv6 = new KeyValuePair <Int32, Double>(3, 2.2);

            KeyValuePair <Int32, Double>[] sorted = new KeyValuePair <Int32, Double>[6]
            {
                kv1, kv2, kv3, kv4, kv5, kv6
            };

            KeyValuePair <Int32, Double>[] notSorted = new KeyValuePair <Int32, Double>[6]
            {
                kv1, kv5, kv2, kv3, kv6, kv4
            };

            KeyIndexedCountingSort.Sort(notSorted, 4);

            AssertUtilities.Sequence(sorted, notSorted);
        }