예제 #1
0
        public void Test1()
        {
            int[] bolts = new int[] { 2, 3, 1, 5, 4 };
            int[] nuts  = new int[] { 5, 2, 3, 4, 1 };
            int   n     = 5;

            Pairs pairs = new Pairs(n, bolts, nuts);

            int[] result = pairs.Solve();

            Assert.AreEqual(n, result.Length);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(nuts[i], bolts[result[i]]);
            }
        }
예제 #2
0
        public void Test2()
        {
            int[] bolts = new int[] { 3, 3, 2, 1, 4, 10 };
            int[] nuts  = new int[] { 10, 1, 4, 3, 2, 3 };
            int   n     = 6;

            Pairs pairs = new Pairs(n, bolts, nuts);

            int[]  result  = pairs.Solve();
            bool[] visited = new bool[n];

            Assert.AreEqual(n, result.Length);

            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(nuts[i], bolts[result[i]]);
                visited[result[i]] = true;
            }

            for (int i = 0; i < n; i++)
            {
                Assert.IsTrue(visited[i]);
            }
        }