<commit_before>﻿using System.Diagnostics;
using NUnit.Framework;
using PurpleKingdomGames.Core;
using PurpleKingdomGames.Core.Pathfinding;
using PurpleKingdomGames.Core.Pathfinding.Seekers;

namespace PurpleKingdomGames.Test.Core.Pathfinding.Seekers
{
    [TestFixture]
    internal class AStarTest
    {
        /// <summary>
        /// Test that we can seek in 2D without additional options
        /// </summary>
        [Test]
        public void TestSeekSimple()
        {
            // The following are marked for clarity
            // S = start
            // A = first target
            // B = second target
            char[,] charGrid = new char[,] {
                { '*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
                { '*', '*', '*', 'x', '*', '*', '*', '*', '*', '*' },
                { '*', '*', '*', 'x', '*', '9', 'x', 'x', 'x', '*' },
                { '*', '*', '*', 'x', '*', '9', 'x', '*', '*', '*' },
                { '*', '*', '*', '*', '*', '9', 'x', '*', '*', '*' },
                { '*', 'S', '*', '*', '*', '9', 'x', '*', '*', 'A' },
                { 'x', '9', 'x', 'x', '*', 'x', 'x', '*', 'x', 'x' },
                { '*', '9', '*', '*', '*', '*', '*', '*', 'x', '*' },
                { 'B', '9', '*', '*', '*', '*', '*', '*', 'x', '*' },
                { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '*' },
            };

            // Initialise the grid
            GridNode2D[,] grid = buildGridFromChars(charGrid);

            Point2D start = new Point2D(1, 5);
            Point2D target = new Point2D(9, 5);
<commit_msg>Adds failing unit tests for an edge case in pathfinding<commit_after>﻿using System.Diagnostics;
using NUnit.Framework;
using PurpleKingdomGames.Core;
using PurpleKingdomGames.Core.Pathfinding;
using PurpleKingdomGames.Core.Pathfinding.Seekers;

namespace PurpleKingdomGames.Test.Core.Pathfinding.Seekers
{
    [TestFixture]
    internal class AStarTest
    {
        /// <summary>
        /// Test that a small grid can be navigated multiple times
        /// </summary>
        [Test]
        public void TestSeekBasicRepeat()
        {
            // The following are marked for clarity
            // S = start
            // A = first target
            // B = second target
            char[,] charGrid = new char[,] {
                { '*', '*', '*', '*', 'S'},
                { 'A', '*', '*', '*', '*'},
                { '*', '*', '*', '*', '*'},
                { '*', '*', '*', '*', '*'},
            };

            // Initialise the grid
            GridNode2D[,] grid = buildGridFromChars(charGrid);

            Point2D start = new Point2D(4, 0);
            Point2D target = new Point2D(0, 1);

            // Repeat 100 times, to catch any oddities on repeated path searches
            for (int i = 0; i < 100; i++) {
                Point2D[] expectedPath = new Point2D[] {
                    new Point2D(4, 0), new Point2D(3, 0), new Point2D(2, 0),
                    new Point2D(1, 0), new Point2D(0, 1)
                };
                Point2D[] path = AStar.Seek(grid, start, target);

                // Check that the path taken was the same as the expected path
                Assert.AreEqual(expectedPath, path, "Path from S to A did not match");
            }
        }

        /// <summary>
        /// Test that we can seek in 2D without additional options
        /// </summary>
        [Test]
        public void TestSeekSimple()
        {
            // The following are marked for clarity
            // S = start
            // A = first target
            // B = second target
            char[,] charGrid = new char[,] {
                { '*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
                { '*', '*', '*', 'x', '*', '*', '*', '*', '*', '*' },
                { '*', '*', '*', 'x', '*', '9', 'x', 'x', 'x', '*' },
                { '*', '*', '*', 'x', '*', '9', 'x', '*', '*', '*' },
                { '*', '*', '*', '*', '*', '9', 'x', '*', '*', '*' },
                { '*', 'S', '*', '*', '*', '9', 'x', '*', '*', 'A' },
                { 'x', '9', 'x', 'x', '*', 'x', 'x', '*', 'x', 'x' },
                { '*', '9', '*', '*', '*', '*', '*', '*', 'x', '*' },
                { 'B', '9', '*', '*', '*', '*', '*', '*', 'x', '*' },
                { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', '*' },
            };

            // Initialise the grid
            GridNode2D[,] grid = buildGridFromChars(charGrid);

            Point2D start = new Point2D(1, 5);
            Point2D target = new Point2D(9, 5);

{'fraction_non_alphanumeric': 0.2495617879053462, 'fraction_numerical': 0.014899211218229623, 'mean_word_length': 1.584937712344281, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4611873', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1420, 'n_words': 331}