Exemplo n.º 1
0
        public void GeneratorPopulatesAllCells(string word)
        {
            var gen     = new StringSearchGenerator();
            int size    = (word.Length * 2);
            var options = new StringSearchGeneratorOptions()
            {
                Width      = size,
                Height     = size,
                Directions = new List <CellDirection>()
                {
                    CellDirection.Right
                }
            };

            options.ItemsToPlace.Add(new TestPuzzleEntry(word, word));

            var puzzle = gen.Generate(options);

            for (int r = 0; r < puzzle.Grid.Rows; r++)
            {
                for (int c = 0; c < puzzle.Grid.Columns; c++)
                {
                    var cell = puzzle.Grid.GetCell(r, c);
                    cell.IsEmpty.Should().BeFalse();
                }
            }
        }
Exemplo n.º 2
0
        public void GeneratorPlacesWordsInGridAndItems(string word1, string word2)
        {
            var gen     = new StringSearchGenerator();
            int size    = (new[] { word1, word2 }.Max(w => w.Length)) * 2;
            var options = new StringSearchGeneratorOptions()
            {
                Width      = size,
                Height     = size,
                Directions = new List <CellDirection>()
                {
                    CellDirection.Right, CellDirection.Down
                }
            };

            options.ItemsToPlace.Add(new TestPuzzleEntry(word1.ToLower(), word1.ToUpper()));
            options.ItemsToPlace.Add(new TestPuzzleEntry(word2.ToLower(), word2.ToUpper()));

            var result = gen.Generate(options);

            result.Grid.Contains(word1.ToUpper()).Should().BeTrue();
            result.Grid.Contains(word2.ToUpper()).Should().BeTrue();

            result.Items.Count(e => e.DisplayValue == word1.ToLower()).Should().Be(1);
            result.Items.Count(e => e.DisplayValue == word2.ToLower()).Should().Be(1);
        }
Exemplo n.º 3
0
        public ActionResult Words(string words, string title)
        {
            var wordList = words
                           .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                           .Select(l => l.Trim())
                           .Where(l => !string.IsNullOrWhiteSpace(l))
                           .ToList();

            var wordItems = wordList
                            .Select(w => new CapitalWordEntry(w))
                            .Cast <IPuzzleEntry>()
                            .ToList();

            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width      = 35,
                Height     = 20,
                Directions = new List <CellDirection>()
                {
                    CellDirection.Right, CellDirection.Down, CellDirection.DownRight
                },
                Title            = title,
                FillerCharacters = Defaults.CapitalAlphabet,
                ItemsToPlace     = wordItems
            };

            var puzzle = gen.GenerateGetMostEntries(options, 1000);

            return(View("Index", puzzle));
        }
Exemplo n.º 4
0
        public void GeneratorOutputsTitle(string title)
        {
            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width  = 5,
                Height = 5,
                Title  = title
            };
            var result = gen.Generate(options);

            result.Title.Should().Be(title);
        }
Exemplo n.º 5
0
        public void GeneratorOutputsRequestedSizeGrid(int width, int height)
        {
            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width  = width,
                Height = height
            };
            var result = gen.Generate(options);

            result.Grid.Columns.Should().Be(width);
            result.Grid.Rows.Should().Be(height);
        }
Exemplo n.º 6
0
        public void GeneratorThrowsExceptionForInvalidSize(int width, int height)
        {
            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width  = width,
                Height = height
            };
            Action test = () =>
            {
                var result = gen.Generate(options);
            };

            test.ShouldThrow <ArgumentException>();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width      = 10,
                Height     = 10,
                Directions = new List <CellDirection>()
                {
                    CellDirection.Right, CellDirection.Down
                },
                Title            = "Test Math Search",
                FillerCharacters = Defaults.Numbers,
            };

            for (int i = 0; i < 100; i++)
            {
                var probs = new List <IMathOperation>()
                {
                    MultiplicationOperation.NewRandom(25, 100),
                    AdditionOperation.NewRandom(100, 100000),
                    SubtractionOperation.NewRandomNonNegative(1, 100),
                    DivisionOperation.NewRandomIntegerResult(10, 100)
                };

                var prob = probs.GetRandom();

                if (prob.ValueDisplay.Length > 1)
                {
                    options.ItemsToPlace.Add(new MathProblemPuzzleEntry(prob));
                }
            }

            var puzzle = gen.Generate(options);

            Console.WriteLine(puzzle.Title);
            Console.WriteLine();
            Console.WriteLine(puzzle.Grid.ToString());
            Console.WriteLine();
            puzzle.Items.ForEach(i => Console.WriteLine(i.DisplayValue));
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 8
0
        public ActionResult Index()
        {
            var gen     = new StringSearchGenerator();
            var options = new StringSearchGeneratorOptions()
            {
                Width      = 15,
                Height     = 15,
                Directions = new List <CellDirection>()
                {
                    CellDirection.Right, CellDirection.Down
                },
                Title            = "Math Search",
                FillerCharacters = Defaults.Numbers,
                ItemsToPlace     = RandomMathProblemsForPuzzle().Take(20).ToList()
            };

            var puzzle = gen.Generate(options);

            return(View(puzzle));
        }
Exemplo n.º 9
0
        public void GeneratorPlacesWordsUsingDesiredDirections(string word, CellDirection direction)
        {
            var gen     = new StringSearchGenerator();
            int size    = (word.Length * 2);
            var options = new StringSearchGeneratorOptions()
            {
                Width      = size,
                Height     = size,
                Directions = new List <CellDirection>()
                {
                    direction
                }
            };

            options.ItemsToPlace.Add(new TestPuzzleEntry(word, word));

            var puzzle = gen.Generate(options);

            var findResult = puzzle.Grid.Find(word).First();

            findResult.Direction.Should().Be(direction);
        }