-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task43Tests.cs
49 lines (44 loc) · 1.45 KB
/
Task43Tests.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
using adventofcode_2021.Task43;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
namespace adventofcode_2021.Tests
{
public class Task43Tests
{
[Fact]
public void Task43_RealExample_Correct()
{
Assert.Equal(2132537931, Solution.Function(ReadFileAsync(Path.Combine("Task43", "Data.txt"))));
}
private IEnumerable<Cuboid> ReadFileAsync(string fileName)
{
foreach (var line in File.ReadLines(fileName))
{
var result = new Cuboid();
string input = string.Empty;
if (line.StartsWith("on "))
{
result.op = true;
input = line.Split("on ")[1];
}
else
{
input = line.Split("off ")[1];
}
var ranges = input.Split(',')
.Select(item => item.Split("=")[1])
.SelectMany(item => item.Split(".."))
.ToList();
result.lowerX = int.Parse(ranges[0]);
result.upperX = int.Parse(ranges[1]);
result.lowerY = int.Parse(ranges[2]);
result.upperY = int.Parse(ranges[3]);
result.lowerZ = int.Parse(ranges[4]);
result.upperZ = int.Parse(ranges[5]);
yield return result;
}
}
}
}