コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }