-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task38Tests.cs
42 lines (39 loc) · 1.22 KB
/
Task38Tests.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
using adventofcode_2021.Task38;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
namespace adventofcode_2021.Tests
{
public class Task38Tests
{
[Fact]
public void Task38_RealExample_Correct()
{
Assert.Equal(3621, Solution.Function(ReadFileAsync(Path.Combine("Task38", "Data.txt"))));
}
private List<HashSet<Point>> ReadFileAsync(string fileName)
{
var result = new List<HashSet<Point>>();
var currentPoints = new HashSet<Point>();
foreach (var line in File.ReadLines(fileName))
{
if (line.StartsWith("--- scanner"))
{
if (currentPoints.Count > 0)
{
result.Add(currentPoints);
currentPoints = new();
}
}
else if (!string.IsNullOrEmpty(line))
{
var n = line.Split(',').Select(x => int.Parse(x)).ToList();
currentPoints.Add(new Point(n[0], n[1], n[2]));
}
}
result.Add(currentPoints);
return result;
}
}
}