-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay04Tests.cs
127 lines (102 loc) · 2.94 KB
/
Day04Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
namespace advent_of_code_csharp_2024;
public class Day04Tests
{
private static string _testInput = @"MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX";
// Part I Filtered
/*
.SAMXMS...
...S..A...
..A.A.MS.X
XMASAMX.MM
X.....XA.A
S.S.S.S.SS
.A.A.A.A.A
..M.M.M.MM
.X.X.XMASX
*/
// Part II Filtered
/*
.M.S......
..A..MSMS.
.M.S.MAA..
..A.ASMSM.
.M.S.M....
..........
S.S.S.S.S.
.A.A.A.A..
M.M.M.M.M.
..........
*/
public static readonly string InputFilename = @"../../../Day04_input.txt";
[Fact]
public void GetCellValueTest()
{
char[][] cells = [
['A','B'],
['C','D']
];
Assert.Equal('A', Day04.GetCellValue(cells, new Day04.Position(0, 0)));
Assert.Equal('B', Day04.GetCellValue(cells, new Day04.Position(1, 0)));
Assert.Equal('C', Day04.GetCellValue(cells, new Day04.Position(0, 1)));
Assert.Equal('D', Day04.GetCellValue(cells, new Day04.Position(1, 1)));
Assert.Equal(' ', Day04.GetCellValue(cells, new Day04.Position(-1, 0)));
Assert.Equal(' ', Day04.GetCellValue(cells, new Day04.Position(0, -1)));
Assert.Equal(' ', Day04.GetCellValue(cells, new Day04.Position(2, 0)));
Assert.Equal(' ', Day04.GetCellValue(cells, new Day04.Position(0, 2)));
}
[Fact(Skip="In progress")]
public void TestExample_part1()
{
char[][] grid = LoadGrid();
Assert.Equal(18, Day04.CountXmas(grid));
}
[Fact(Skip="In progress")]
public void TestRealData_part1()
{
var lines = File.ReadLines(InputFilename);
char[][] grid = LinesToChars(lines);
Assert.Equal(2613, Day04.CountXmas(grid));
}
[Fact]
public void TestExample_part2()
{
char[][] grid = LoadGrid();
Assert.Equal(9, Day04.CountXmas(grid));
}
[Fact]
public void TestRealData_part2()
{
var lines = File.ReadLines(InputFilename);
char[][] grid = LinesToChars(lines);
Assert.Equal(1905, Day04.CountXmas(grid));
}
private static char[][] LoadGrid()
{
var lines = _testInput.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
return LinesToChars(lines);
}
private static char[][] LinesToChars(IEnumerable<string> lines){
return lines
.Select(line => line.ToCharArray().Where(c => !char.IsWhiteSpace(c)).ToArray())
.ToArray();
}
[Fact]
public void XmaxCellCountTest(){
var grid = LoadGrid();
Assert.False(Day04.IsXmasCell(grid, new Day04.Position(0,0)));
Assert.True(Day04.IsXmasCell(grid, new Day04.Position(2,1)));
Assert.True(Day04.IsXmasCell(grid, new Day04.Position(6,2)));
// Assert.Equal(2, Day04.XmasCellCount(grid, new Day04.Position(6,4)));
// Assert.Equal(2, Day04.XmasCellCount(grid, new Day04.Position(6,4)));
// Assert.Equal(3, Day04.XmasCellCount(grid, new Day04.Position(5,9)));
}
}