|
| 1 | +using AdventOfCode.Elves.IOHelpers; |
| 2 | +using FluentAssertions; |
| 3 | +using Moq; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Text; |
| 7 | + |
| 8 | +namespace AdventOfCode2025.Tests |
| 9 | +{ |
| 10 | + internal class DayOneTests |
| 11 | + { |
| 12 | + [TestCase("R19")] |
| 13 | + [TestCase("R29")] |
| 14 | + [TestCase("R39")] |
| 15 | + [TestCase("R49")] |
| 16 | + public void NoHitRotation_Should_Count_0_Hits(string input) |
| 17 | + { |
| 18 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 19 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input }); |
| 20 | + StringBuilder sb = new(); |
| 21 | + StringWriter sw = new StringWriter(sb); |
| 22 | + Console.SetOut(sw); |
| 23 | + |
| 24 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 25 | + |
| 26 | + dayOne.PartTwo(); |
| 27 | + |
| 28 | + sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 0"); |
| 29 | + } |
| 30 | + |
| 31 | + [TestCase("R50")] |
| 32 | + public void Going_Up_To_100_Should_Count_1_Hit(string input) |
| 33 | + { |
| 34 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 35 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input }); |
| 36 | + StringBuilder sb = new(); |
| 37 | + StringWriter sw = new StringWriter(sb); |
| 38 | + Console.SetOut(sw); |
| 39 | + |
| 40 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 41 | + |
| 42 | + dayOne.PartTwo(); |
| 43 | + |
| 44 | + sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1"); |
| 45 | + } |
| 46 | + |
| 47 | + [TestCase("L50")] |
| 48 | + public void Going_Down_To_0_Should_Count_1_Hit(string input) |
| 49 | + { |
| 50 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 51 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(new List<string> { input }); |
| 52 | + StringBuilder sb = new(); |
| 53 | + StringWriter sw = new StringWriter(sb); |
| 54 | + Console.SetOut(sw); |
| 55 | + |
| 56 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 57 | + |
| 58 | + dayOne.PartTwo(); |
| 59 | + |
| 60 | + sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1"); |
| 61 | + } |
| 62 | + |
| 63 | + [TestCase("R29,R21")] |
| 64 | + public void Going_Up_To_100_In_Two_Moves_Should_Count_1_Hit(string inputLines) |
| 65 | + { |
| 66 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 67 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList()); |
| 68 | + StringBuilder sb = new(); |
| 69 | + StringWriter sw = new StringWriter(sb); |
| 70 | + Console.SetOut(sw); |
| 71 | + |
| 72 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 73 | + |
| 74 | + dayOne.PartTwo(); |
| 75 | + |
| 76 | + sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1"); |
| 77 | + } |
| 78 | + |
| 79 | + [TestCase("L29,L21")] |
| 80 | + public void Going_Down_To_0_In_Two_Moves_Should_Count_1_Hit(string inputLines) |
| 81 | + { |
| 82 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 83 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList()); |
| 84 | + StringBuilder sb = new(); |
| 85 | + StringWriter sw = new StringWriter(sb); |
| 86 | + Console.SetOut(sw); |
| 87 | + |
| 88 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 89 | + |
| 90 | + dayOne.PartTwo(); |
| 91 | + |
| 92 | + sb.ToString().Trim().Should().Be("Part Two: Number of 0 mid-rotation hits 1"); |
| 93 | + } |
| 94 | + |
| 95 | + [TestCase("R1000", 10)] |
| 96 | + [TestCase("R50,R200", 3)] |
| 97 | + [TestCase("L50,L200", 3)] |
| 98 | + public void Passing_0_Multiple_Times_In_One_Move_Should_Count_All_Hits(string inputLines, int hits) |
| 99 | + { |
| 100 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 101 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList()); |
| 102 | + StringBuilder sb = new(); |
| 103 | + StringWriter sw = new StringWriter(sb); |
| 104 | + Console.SetOut(sw); |
| 105 | + |
| 106 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 107 | + |
| 108 | + dayOne.PartTwo(); |
| 109 | + |
| 110 | + sb.ToString().Trim().Should().Be($"Part Two: Number of 0 mid-rotation hits {hits}"); |
| 111 | + } |
| 112 | + |
| 113 | + [TestCase("L68,L30,R48,L5,R60,L55,L1,L99,R14,L82", 6)] |
| 114 | + public void Complex_Cases_Should_Be_Handled_Correctly(string inputLines, int hits) |
| 115 | + { |
| 116 | + Mock<IPuzzleInputHelper> mockInputHelper = new Mock<IPuzzleInputHelper>(); |
| 117 | + mockInputHelper.Setup(m => m.GetInputLines(It.IsAny<string>())).Returns(inputLines.Split(",").ToList()); |
| 118 | + StringBuilder sb = new(); |
| 119 | + StringWriter sw = new StringWriter(sb); |
| 120 | + Console.SetOut(sw); |
| 121 | + |
| 122 | + DayOne dayOne = new DayOne(mockInputHelper.Object); |
| 123 | + |
| 124 | + dayOne.PartTwo(); |
| 125 | + |
| 126 | + sb.ToString().Trim().Should().Be($"Part Two: Number of 0 mid-rotation hits {hits}"); |
| 127 | + } |
| 128 | + } |
| 129 | +} |
0 commit comments