public void EmptyStringToValidateCost()
 {
     TestProgram _testProgram = new TestProgram();
     string str1 = "";
     string str2 = "";
     int expected = 0;
     var actual = _testProgram.Cost(str1, str2);
     Assert.AreEqual(expected, actual);
 }
        public void LeftLowerToValidateGridCost()
        {
            TestProgram _testProgram = new TestProgram();
            //	Present a big text input area in which a reasonably large text can be written or pasted.
            int sx = 0;
            int sy = 3;
            int[] sCost = new int[8];
            const int MAXINT = 3000;
            string str1 = "or";
            string str2 = "pasted";
            string str3 = "large";
            string str4 = "text";
            for (int i = 0; i < 8; i++)
            {
                sCost[i] = MAXINT;
            }
            _testProgram.pWord[sx, sy] = str1;
            _testProgram.pWord[sx + 1, sy] = str2;
            _testProgram.pWord[sx, sy - 1] = str3;
            _testProgram.pWord[sx + 1, sy - 1] = str4;
            if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)
                && !string.IsNullOrEmpty(str3) && !string.IsNullOrEmpty(str4))
            {
                sCost[0] = _testProgram.Cost(str1.ToUpper(), str2.ToUpper());
                sCost[3] = _testProgram.Cost(str1.ToUpper(), str3.ToUpper());
                sCost[6] = _testProgram.Cost(str1.ToUpper(), str4.ToUpper());
            }

            int expected = 0;
            int actual = 0;
            _testProgram.GridCost(sx, sy);
            if ((sCost[0] == _testProgram.G[sx + sy * _testProgram.nWidth, sx+1+ sy * _testProgram.nWidth])
                && (sCost[3] == _testProgram.G[sx + sy * _testProgram.nWidth, sx + (sy-1)* _testProgram.nWidth])
                && (sCost[6] == _testProgram.G[sx + sy * _testProgram.nWidth, sx+1 + (sy - 1) * _testProgram.nWidth]))
            {
                actual = 0;
            }
            else
                actual = 1;
            Assert.AreEqual(expected, actual);
        }
        public void LeftUpperToValidateGridCost()
        {
            TestProgram _testProgram = new TestProgram();
            int sx = 0;
            int sy = 0;
            int[] sCost = new int[8];
            const int MAXINT = 3000;
            string str1 = "Present";
            string str2 = "a";
            string str3 = "area";
            string str4 = "in";
            for (int i = 0; i < 8; i++)
            {
                sCost[i] = MAXINT;
            }
            _testProgram.pWord[sx, sy] = str1;
            _testProgram.pWord[sx+1, sy] = str2;
            _testProgram.pWord[sx, sy+1] = str3;
            _testProgram.pWord[sx+1, sy+1] = str4;
            if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)
                && !string.IsNullOrEmpty(str3) && !string.IsNullOrEmpty(str4))
            {
                sCost[0] = _testProgram.Cost(str1.ToUpper(), str2.ToUpper());
                sCost[2] = _testProgram.Cost(str1.ToUpper(), str3.ToUpper());
                sCost[4] = _testProgram.Cost(str1.ToUpper(), str4.ToUpper());
            }

            int expected = 0;
            int actual = 0;
            _testProgram.GridCost(sx, sy);
            if ((sCost[0] == _testProgram.G[0,1])
                && (sCost[2] == _testProgram.G[0,_testProgram.nWidth])
                && (sCost[4] == _testProgram.G[0,1+_testProgram.nWidth]))
            {
                actual = 0;
            }
            else
                actual = 1;
            Assert.AreEqual(expected, actual);
        }
        public void RightUpperToValidateGridCost()
        {
            TestProgram _testProgram = new TestProgram();

            int sx = 4;
            int sy = 0;
            int[] sCost = new int[8];
            const int MAXINT = 3000;
            string str1 = "input";
            string str2 = "text";
            string str3 = "reasonably";
            string str4 = "a";
            for (int i = 0; i < 8; i++)
            {
                sCost[i] = MAXINT;
            }
            _testProgram.pWord[sx, sy] = str1;
            _testProgram.pWord[sx - 1, sy] = str2;
            _testProgram.pWord[sx, sy + 1] = str3;
            _testProgram.pWord[sx - 1, sy + 1] = str4;
            if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2)
                && !string.IsNullOrEmpty(str3) && !string.IsNullOrEmpty(str4))
            {
                sCost[1] = _testProgram.Cost(str1.ToUpper(), str2.ToUpper());
                sCost[2] = _testProgram.Cost(str1.ToUpper(), str3.ToUpper());
                sCost[5] = _testProgram.Cost(str1.ToUpper(), str4.ToUpper());
            }
            int expected = 0;
            int actual = 0;
            _testProgram.GridCost(sx, sy);
            if ((sCost[1] == _testProgram.G[sx + sy * _testProgram.nWidth, _testProgram.nWidth - 2])
                && (sCost[2] == _testProgram.G[sx + sy * _testProgram.nWidth, 2 * _testProgram.nWidth - 1])
                && (sCost[5] == _testProgram.G[sx + sy * _testProgram.nWidth, 2 * _testProgram.nWidth - 2]))
            {
                actual = 0;
            }
            else
                actual = 1;
            Assert.AreEqual(expected, actual);
        }
        public void OneWordValidategetShortestPath()
        {
            TestProgram _testProgram = new TestProgram();
            string expected = "";
            string actual = "";
            int num_words = 1;
            _testProgram.InitG();
            int[] path1 = new int[num_words];
            int dist1 = _testProgram.getShortestPath(_testProgram.G, 0, num_words - 1, path1);
            expected = "0";
            for (int i = 0; i < path1.Length; i++)
                actual += path1[i].ToString();

            Assert.AreEqual(expected, actual);
        }
        public void OneLineValidategetShortestPath()
        {
            TestProgram _testProgram = new TestProgram();
            string expected = "";
            string actual = "";
            int num_words = 4;
            _testProgram.InitG();
            _testProgram.G[0, 1] = 15;
            _testProgram.G[1, 0] = 15;
            _testProgram.G[1, 2] = 1;
            _testProgram.G[2, 1] = 1;
            _testProgram.G[2, 3] = 18;
            _testProgram.G[3, 2] = 18;
            int[] path1 = new int[num_words];
            int dist1 = _testProgram.getShortestPath(_testProgram.G, 0, num_words-1, path1);
            expected = "0123";
            for (int i = 0; i < path1.Length; i++)
                actual+=path1[i].ToString();

            Assert.AreEqual(expected, actual);
        }
 public void NormalStringToValidateCost()
 {
     TestProgram _testProgram = new TestProgram();
     string str1 = "fu";
     string str2 = "chen";
     int expected = 0;
     if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
     {
         byte[] asciiBytesStr1 = Encoding.ASCII.GetBytes(str1.ToUpper());
         byte[] asciiBytesStr2 = Encoding.ASCII.GetBytes(str2.ToUpper());
         expected = Math.Abs((int)(asciiBytesStr1[0]) - (int)(asciiBytesStr2[0]));
     }
     var actual = _testProgram.Cost(str1, str2);
     Assert.AreEqual(expected, actual);
 }
        public void MultipleLineValidategetShortestPath()
        {
            TestProgram _testProgram = new TestProgram();
            string expected = "";
            string actual = "";
            int num_words = 9;
            _testProgram.InitG();
            _testProgram.G[0, 1] = 15;
            _testProgram.G[0, 5] = 15;
            _testProgram.G[0, 6] = 7;
            _testProgram.G[1, 0] = 15;
            _testProgram.G[1, 2] = 1;
            _testProgram.G[1, 5] = 0;
            _testProgram.G[1, 6] = 8;
            _testProgram.G[1, 7] = 22;
            _testProgram.G[2, 1] = 1;
            _testProgram.G[2, 3] = 18;
            _testProgram.G[2, 6] = 7;
            _testProgram.G[2, 7] = 21;
            _testProgram.G[2, 8] = 1;
            _testProgram.G[3, 2] = 18;
            _testProgram.G[3, 4] = 11;
            _testProgram.G[3, 7] = 3;
            _testProgram.G[3, 8] = 19;
            _testProgram.G[4, 3] = 11;
            _testProgram.G[4, 8] = 8;
            _testProgram.G[5, 0] = 15;
            _testProgram.G[5, 1] = 0;
            _testProgram.G[5, 6] = 8;
            _testProgram.G[6, 0] = 7;
            _testProgram.G[6, 1] = 8;
            _testProgram.G[6, 2] = 7;
            _testProgram.G[6, 5] = 8;
            _testProgram.G[6, 7] = 14;
            _testProgram.G[7, 1] = 22;
            _testProgram.G[7, 2] = 21;
            _testProgram.G[7, 3] = 3;
            _testProgram.G[7, 6] = 14;
            _testProgram.G[7, 8] = 22;
            _testProgram.G[8, 2] = 1;
            _testProgram.G[8, 3] = 19;
            _testProgram.G[8, 4] = 8;
            _testProgram.G[8, 7] = 22;
            int[] path1 = new int[num_words];
            int dist1 = _testProgram.getShortestPath(_testProgram.G, 0, num_words-1, path1);
            expected = "062800000";
            for (int i = 0; i < path1.Length; i++)
                actual += path1[i].ToString();

            Assert.AreEqual(expected, actual);
        }
        public void MiddleToValidateGridCost()
        {
            TestProgram _testProgram = new TestProgram();
            //	Present a big text input area in which a reasonably large text can be written or pasted.
            int sx = 2;
            int sy = 1;
            int[] sCost = new int[8];
            const int MAXINT = 3000;

            string str0 = "which";
            string str1 = "a";
            string str2 = "in";
            string str3 = "can";
            string str4 = "big";
            string str5 = "be";
            string str6 = "text";
            string str7 = "text";
            string str8 = "a";
            for (int i = 0; i < 8; i++)
            {
                sCost[i] = MAXINT;
            }
            _testProgram.pWord[sx, sy] = str0;
            _testProgram.pWord[sx + 1, sy] = str1;
            _testProgram.pWord[sx-1, sy] = str2;
            _testProgram.pWord[sx, sy + 1] = str3;
            _testProgram.pWord[sx, sy - 1] = str4;
            _testProgram.pWord[sx + 1, sy + 1] = str5;
            _testProgram.pWord[sx - 1, sy + 1] = str6;
            _testProgram.pWord[sx + 1, sy - 1] = str7;
            _testProgram.pWord[sx - 1, sy - 1] = str8;

            if (!string.IsNullOrEmpty(str0) && !string.IsNullOrEmpty(str1)
                && !string.IsNullOrEmpty(str2) && !string.IsNullOrEmpty(str3)
                && !string.IsNullOrEmpty(str4) && !string.IsNullOrEmpty(str5)
                && !string.IsNullOrEmpty(str6) && !string.IsNullOrEmpty(str7)
                && !string.IsNullOrEmpty(str8))
            {
                sCost[0] = _testProgram.Cost(str0.ToUpper(), str1.ToUpper());
                sCost[1] = _testProgram.Cost(str0.ToUpper(), str2.ToUpper());
                sCost[2] = _testProgram.Cost(str0.ToUpper(), str3.ToUpper());
                sCost[3] = _testProgram.Cost(str0.ToUpper(), str4.ToUpper());
                sCost[4] = _testProgram.Cost(str0.ToUpper(), str5.ToUpper());
                sCost[5] = _testProgram.Cost(str0.ToUpper(), str6.ToUpper());
                sCost[6] = _testProgram.Cost(str0.ToUpper(), str7.ToUpper());
                sCost[7] = _testProgram.Cost(str0.ToUpper(), str8.ToUpper());
            }

            int expected = 0;
            int actual = 0;
            _testProgram.GridCost(sx, sy);
            int[] px = new int[] { 1, -1, 0, 0, 1, -1, 1, -1 };   // x axis offset
            int[] py = new int[] { 0, 0, 1, -1, 1, 1, -1, -1 };   // y axis offset
            if ((sCost[0] == _testProgram.G[sx + sy * _testProgram.nWidth, sx + 1 + sy * _testProgram.nWidth])
                && (sCost[1] == _testProgram.G[sx + sy * _testProgram.nWidth, sx-1 + sy * _testProgram.nWidth])
                && (sCost[2] == _testProgram.G[sx + sy * _testProgram.nWidth, sx + (sy + 1) * _testProgram.nWidth])
                && (sCost[3] == _testProgram.G[sx + sy * _testProgram.nWidth, sx + (sy - 1) * _testProgram.nWidth])
                && (sCost[4] == _testProgram.G[sx + sy * _testProgram.nWidth, sx+1 + (sy + 1) * _testProgram.nWidth])
                && (sCost[5] == _testProgram.G[sx + sy * _testProgram.nWidth, sx-1 + (sy + 1) * _testProgram.nWidth])
                && (sCost[6] == _testProgram.G[sx + sy * _testProgram.nWidth, sx + 1 + (sy - 1) * _testProgram.nWidth])
                && (sCost[7] == _testProgram.G[sx + sy * _testProgram.nWidth, sx-1 + (sy - 1) * _testProgram.nWidth]))
            {
                actual = 0;
            }
            else
                actual = 1;
            Assert.AreEqual(expected, actual);
        }