Example #1
0
        public void CalculatesCorrectDistanceFromOrigin()
        {
            var map = new SpiralMemory(1);

            // Create all the entries
            foreach (var unused in map.GenerateEntries())
            {
            }
            Assert.AreEqual(0, map.DistanceFromOrigin());

            map = new SpiralMemory(12);
            foreach (var unused in map.GenerateEntries())
            {
            }
            Assert.AreEqual(3, map.DistanceFromOrigin());

            map = new SpiralMemory(23);
            foreach (var unused in map.GenerateEntries())
            {
            }
            Assert.AreEqual(2, map.DistanceFromOrigin());

            map = new SpiralMemory(1024);
            foreach (var unused in map.GenerateEntries())
            {
            }
            Assert.AreEqual(31, map.DistanceFromOrigin());
        }
Example #2
0
        public void Execute_Always_ReturnsCorrectResult(int input, int expectedResult)
        {
            var sut    = new SpiralMemory();
            var result = sut.Evaluate(input);

            result.ShouldBe(expectedResult);
        }
Example #3
0
        public void FindGridRange_Should_Return_Correct_Range(int number, int sqrt, int sequnce, int start, int end)
        {
            var result = SpiralMemory.FindGridRange(number, sqrt, sequnce);

            result.start.Should().Be(start);
            result.end.Should().Be(end);
        }
Example #4
0
        public void CalculateStepsFromMemoryLocation(int memoryLocation, int expectedSteps)
        {
            var sprialMemory = new SpiralMemory(memoryLocation);
            var memoryBlock  = sprialMemory.GetMemoryBlock(memoryLocation);

            Assert.Equal(expectedSteps, memoryBlock.CalculateSteps());
        }
Example #5
0
        public void CalculateValueFromMemoryLocation(int memoryLocation, ulong expectedValue)
        {
            var sprialMemory = new SpiralMemory(memoryLocation);
            var memoryBlock  = sprialMemory.GetMemoryBlock(memoryLocation);

            Assert.Equal(expectedValue, memoryBlock.Value);
        }
        public void ShouldReturnCorrectSteps(int input, int expected)
        {
            var spiralMemory = new SpiralMemory();

            var result = spiralMemory.GetSteps(input);

            Assert.Equal(expected, result);
        }
Example #7
0
        public void SpiralMemory_NextValue_LargerThanFive()
        {
            // act
            var result = SpiralMemory.FindNextValue(5);

            // assert
            Assert.AreEqual(10, result);
        }
        public void NumberOfStepsRequiredFromCenterTo(int numberOfMemoryLocations, int expectedNumberOfSteps)
        {
            SpiralMemory memory = SpiralMemory.Generate(numberOfMemoryLocations);

            Position position = memory[numberOfMemoryLocations - 1].Position;

            Assert.Equal(expectedNumberOfSteps, Math.Abs(position.X) + Math.Abs(position.Y));
        }
Example #9
0
        public void SpiralMemory_StepsToOrigin_Straight()
        {
            // act
            var result = SpiralMemory.FindStepsToOrigin(23);

            // assert
            Assert.AreEqual(2, result);
        }
Example #10
0
        public void SpiralMemory_StepsToOrigin_LargeNumber()
        {
            // act
            var result = SpiralMemory.FindStepsToOrigin(1024);

            // assert
            Assert.AreEqual(31, result);
        }
Example #11
0
        public void SpiralMemory_StepsToOrigin_AtOrigin()
        {
            // act
            var result = SpiralMemory.FindStepsToOrigin(1);

            // assert
            Assert.AreEqual(0, result);
        }
Example #12
0
        public void SpiralMemory_StepsToOrigin_Diagonal()
        {
            // act
            var result = SpiralMemory.FindStepsToOrigin(12);

            // assert
            Assert.AreEqual(3, result);
        }
Example #13
0
        public void SpiralMemory_NextValue_LargerThanTwo()
        {
            // act
            var result = SpiralMemory.FindNextValue(2);

            // assert
            Assert.AreEqual(4, result);
        }
Example #14
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Day1 Answer: {InverseCaptcha.CalcSum()}");
            Console.WriteLine($"Day1 Part2 Answer: {InverseCaptcha.CalcSumPart2()}");

            var day2InputPuzzle = System.IO.File.ReadAllText("Day2\\InputPuzzleDay2.txt");

            Console.WriteLine($"Day2 Answer: {CorruptionChecksum.CalculateCheckSum(day2InputPuzzle)}");
            Console.WriteLine($"Day1 Part2 Answer: {CorruptionChecksum.CalculateCheckSum_Part2(day2InputPuzzle)}");

            Console.WriteLine($"Day3 Answer: {SpiralMemory.CalculateSteps(289326)}");


            if (Debugger.IsAttached)
            {
                Console.ReadKey();
            }
        }
Example #15
0
        public void CanCreateStressTestMemoryMap()
        {
            var map      = new SpiralMemory(1);
            var actual   = map.GenerateStressTestEntries(100);
            var expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(0, 0, 1)
            };

            CheckMemoryEntriesEqual(expected, actual);

            map      = new SpiralMemory(4);
            actual   = map.GenerateStressTestEntries(100);
            expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(0, 0, 1),
                new SpiralMemoryEntry(1, 0, 1),
                new SpiralMemoryEntry(1, 1, 2),
                new SpiralMemoryEntry(0, 1, 4)
            };

            CheckMemoryEntriesEqual(expected, actual);

            map      = new SpiralMemory(9);
            actual   = map.GenerateStressTestEntries(100);
            expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(1, 1, 1),
                new SpiralMemoryEntry(2, 1, 1),
                new SpiralMemoryEntry(2, 2, 2),
                new SpiralMemoryEntry(1, 2, 4),
                new SpiralMemoryEntry(0, 2, 5),
                new SpiralMemoryEntry(0, 1, 10),
                new SpiralMemoryEntry(0, 0, 11),
                new SpiralMemoryEntry(1, 0, 23),
                new SpiralMemoryEntry(2, 0, 25)
            };

            CheckMemoryEntriesEqual(expected, actual);
        }
Example #16
0
        public void CanCreateMemoryMap()
        {
            var map      = new SpiralMemory(1);
            var actual   = map.GenerateEntries();
            var expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(0, 0, 1)
            };

            CheckMemoryEntriesEqual(expected, actual);

            map      = new SpiralMemory(4);
            actual   = map.GenerateEntries();
            expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(0, 0, 1),
                new SpiralMemoryEntry(1, 0, 2),
                new SpiralMemoryEntry(1, 1, 3),
                new SpiralMemoryEntry(0, 1, 4)
            };

            CheckMemoryEntriesEqual(expected, actual);

            map      = new SpiralMemory(9);
            actual   = map.GenerateEntries();
            expected = new List <SpiralMemoryEntry> {
                new SpiralMemoryEntry(1, 1, 1),
                new SpiralMemoryEntry(2, 1, 2),
                new SpiralMemoryEntry(2, 2, 3),
                new SpiralMemoryEntry(1, 2, 4),
                new SpiralMemoryEntry(0, 2, 5),
                new SpiralMemoryEntry(0, 1, 6),
                new SpiralMemoryEntry(0, 0, 7),
                new SpiralMemoryEntry(1, 0, 8),
                new SpiralMemoryEntry(2, 0, 9)
            };

            CheckMemoryEntriesEqual(expected, actual);
        }
 public void OneTimeSetUp()
 {
     _memory = new SpiralMemory();
 }
        public void FirstNumberHigherThan(int number, int expectedNumber)
        {
            SpiralMemory memory = SpiralMemory.GenerateUntilLastValueIsHigherThan(number);

            Assert.Equal(expectedNumber, memory[memory.Count - 1].Value);
        }
Example #19
0
 public Part1()
 {
     inputSquareRepository = new InputSquareRepository();
     spiralMemory          = new SpiralMemory();
 }
Example #20
0
 public void Start()
 {
     spiralMemory = new SpiralMemory();
 }
Example #21
0
 public void OddNumberOrder_Should_Return_Correct_Number(int num, int expected)
 {
     SpiralMemory.OddNumberOrder(num).Should().Be(expected);
 }
Example #22
0
        public void OddNumberOrder_Should_Throw_Error_When_Even_Number_Supplied(int even)
        {
            Action a = () => SpiralMemory.OddNumberOrder(even);

            a.ShouldThrowExactly <ArgumentException>();
        }
Example #23
0
 public void FindMediun_Should_Return_Correct_Number(int start, int end, int expected)
 {
     SpiralMemory.FindMedian(start, end).Should().Be(expected);
 }
        public void MemoryLocationsGoInSpiral(int numberOfMemoryLocations, int x, int y)
        {
            SpiralMemory memory = SpiralMemory.Generate(numberOfMemoryLocations);

            Assert.Equal(new Position(x, y), memory[numberOfMemoryLocations - 1].Position);
        }
Example #25
0
 public void CalculateSteps_Should_Return_Correct_Step_Count(int number, int steps)
 {
     SpiralMemory.CalculateSteps(number).Should().Be(steps);
 }
Example #26
0
 public void FindSquareRoot_Should_Return_Correct_Number(int num, int expected)
 {
     SpiralMemory.FindSquareRoot(num).value.Should().Be(expected);
 }
 public void Setup()
 {
     ClassUnderTest = new SpiralMemory();
 }