コード例 #1
0
        public void Given4x4WordSearchPuzzleWhenPassingKToGetAllLocationsOfLetterThenGetAllLocationsOfLetterDoesNotReturnNull(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut = CreateInstance(puzzle);

            List <Vector2> result = sut.GetAllLocationsOfLetter('K');

            Assert.IsNotNull(result);
        }
コード例 #2
0
        public void Given4x4WordSearchPuzzleWhenPassingEToGetAllLocationsOfLetterThenGetAllLocationsOfLetterReturnsLocationOf1E(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut = CreateInstance(puzzle);

            List <Vector2> result   = sut.GetAllLocationsOfLetter('E');
            List <Vector2> expected = new List <Vector2>();

            expected.Add(new Vector2(1, 0));

            Assert.AreEqual(expected, result);
        }
コード例 #3
0
        public void Given4x4WordSearchPuzzleWhenPassingStarting00and4ToGetNeighborsFromThenGetNeighborsFromDoesNotReturnNull(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut = CreateInstance(puzzle);

            Vector2 startLocation = new Vector2(0, 0);
            int     length        = 4;

            List <Vector2> result = sut.GetNeighborsFrom(startLocation, length);

            Assert.IsNotNull(result);
        }
コード例 #4
0
        public void Given5x5WordSearchPuzzleWhenPassing22And5ToGetNeighborsFromThenGetNeighborsFromReturnsVector2ListWith3Elements(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut = CreateInstance(puzzle);

            Vector2        startLocation = new Vector2(2, 2);
            int            length        = 5;
            List <Vector2> locations     = sut.GetNeighborsFrom(startLocation, length);

            int result   = locations.Count;
            int expected = 3;

            Assert.AreEqual(expected, result);
        }
コード例 #5
0
        public void Given4x4WordSearchPuzzleWhenFirstRowLocationListToGetStringFromLocationsThenGetStringFromLocationsDoesNotReturnNull(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut      = CreateInstance(puzzle);
            List <Vector2>           firstRow = new List <Vector2>();

            firstRow.Add(new Vector2(0, 0));
            firstRow.Add(new Vector2(1, 0));
            firstRow.Add(new Vector2(2, 0));
            firstRow.Add(new Vector2(3, 0));

            String result = sut.GetStringFromLocations(firstRow);

            Assert.IsNotNull(result);
        }
コード例 #6
0
        public void Given4x4WordSearchPuzzleWhenSecondRowLocationListToGetStringFromLocationsThenGetStringFromLocationsReturnsRRJA(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut       = CreateInstance(puzzle);
            List <Vector2>           secondRow = new List <Vector2>();

            secondRow.Add(new Vector2(0, 1));
            secondRow.Add(new Vector2(1, 1));
            secondRow.Add(new Vector2(2, 1));
            secondRow.Add(new Vector2(3, 1));

            String result   = sut.GetStringFromLocations(secondRow);
            String expected = "RRJA";

            Assert.AreEqual(expected, result);
        }
コード例 #7
0
        public void Given4x4WordSearchPuzzleWhenFirstRowLocationListToGetStringFromLocationsThenGetStringFromLocationsReturnsKEFN(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut      = CreateInstance(puzzle);
            List <Vector2>           firstRow = new List <Vector2>();

            firstRow.Add(new Vector2(0, 0));
            firstRow.Add(new Vector2(1, 0));
            firstRow.Add(new Vector2(2, 0));
            firstRow.Add(new Vector2(3, 0));

            String result   = sut.GetStringFromLocations(firstRow);
            String expected = "KEFN";

            Assert.AreEqual(expected, result);
        }
コード例 #8
0
        public void Given4x4WordSearchPuzzleWhenPassing23And3ToGetNeighborsFromThenGetNeighborsFromReturnsListOfLocationsFrom23UpLeft(WordSearchPuzzle puzzle)
        {
            IDirectionSearchStrategy sut = CreateInstance(puzzle);

            Vector2 startLocation = new Vector2(2, 3);
            int     length        = 3;

            List <Vector2> result   = sut.GetNeighborsFrom(startLocation, length);
            List <Vector2> expected = new List <Vector2>();

            expected.Add(new Vector2(2, 3));
            expected.Add(new Vector2(1, 2));
            expected.Add(new Vector2(0, 1));

            Assert.AreEqual(expected, result);
        }
コード例 #9
0
        private List <Vector2> SearchWordInDirection(String word, IDirectionSearchStrategy directionSearchStrategy)
        {
            List <Vector2> wordPosition         = new List <Vector2>();
            List <Vector2> firstLetterLocations = directionSearchStrategy.GetAllLocationsOfLetter(word[FIRST_LETTER_OF_WORD_INDEX]);

            foreach (Vector2 location in firstLetterLocations)
            {
                List <Vector2> candidate = directionSearchStrategy.GetNeighborsFrom(location, word.Length);
                String         foundWord = directionSearchStrategy.GetStringFromLocations(candidate);

                if (word.Equals(foundWord))
                {
                    wordPosition.AddRange(candidate);
                }
            }

            return(wordPosition);
        }