-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task39Tests.cs
91 lines (79 loc) · 2.54 KB
/
Task39Tests.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
using adventofcode_2021.Task39;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Xunit;
using Xunit.Abstractions;
namespace adventofcode_2021.Tests
{
public class Task39Tests
{
public Task39Tests(ITestOutputHelper output)
{
var converter = new Converter(output);
Console.SetOut(converter);
}
[Fact]
public void Task39_RealExample_Correct()
{
Assert.Equal(35, Solution.Function(ReadFileAsync(Path.Combine("Task39", "Data.txt"))));
}
private (string, List<string>) ReadFileAsync(string fileName)
{
string algorithmString = string.Empty;
bool shouldReadImage = false;
List<string> result = new();
var dots = new string('.', 4);
foreach (var line in File.ReadLines(fileName))
{
if (string.IsNullOrEmpty(line))
{
shouldReadImage = true;
continue;
}
if (!shouldReadImage)
{
algorithmString += line;
continue;
}
result.Add($"{dots}{line}{dots}");
}
var resultWithBorder = new List<string>();
for (int i = 0; i < 4; i++)
{
resultWithBorder.Add(new string('.', result[0].Length));
}
resultWithBorder.AddRange(result);
for (int i = 0; i < 4; i++)
{
resultWithBorder.Add(new string('.', result[0].Length));
}
return (algorithmString, resultWithBorder);
}
private class Converter : TextWriter
{
ITestOutputHelper _output;
public Converter(ITestOutputHelper output)
{
_output = output;
}
public override Encoding Encoding
{
get { return Encoding.Default; }
}
public override void WriteLine(string message)
{
_output.WriteLine(message);
}
public override void WriteLine(string format, params object[] args)
{
_output.WriteLine(format, args);
}
public override void Write(char value)
{
throw new NotSupportedException("This text writer only supports WriteLine(string) and WriteLine(string, params object[]).");
}
}
}
}