-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay22Task1Tests.cs
More file actions
126 lines (100 loc) · 2.95 KB
/
Day22Task1Tests.cs
File metadata and controls
126 lines (100 loc) · 2.95 KB
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
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode2020.Tests
{
[TestFixture]
public class Day22Task1Tests
{
Day22Task1 Solver() => new Day22Task1();
string Example() => @"Player 1:
9
2
6
3
1
Player 2:
5
8
4
7
10";
[Test]
public void solves_example()
{
var input = Example();
var solver = Solver();
var result = solver.Solve(input);
result.Should().Be(306);
}
[Test]
public void parses_example()
{
var input = Example();
var solver = Solver();
var (p1, p2) = solver.Parse(input);
p1.Should().ContainInOrder(new[] { 9, 2, 6, 3, 1 });
p2.Should().ContainInOrder(new[] { 5, 8, 4, 7, 10 });
}
[Test]
public void player1_wins_first_round()
{
var input = Example();
var solver = Solver();
var (p1, p2) = solver.Parse(input);
int round = 0;
var winners = new List<int>();
solver.PlayOneRound(p1, p2, ref round, winners);
p1.Should().ContainInOrder(new[] { 2, 6, 3, 1, 9, 5 });
p2.Should().ContainInOrder(new[] { 8, 4, 7, 10 });
round.Should().Be(1);
winners.Should().ContainInOrder(new[] { 1 });
}
[Test]
public void player2_wins_second_round()
{
var input = Example();
var solver = Solver();
var (p1, p2) = solver.Parse(input);
int round = 0;
var winners = new List<int>();
solver.PlayOneRound(p1, p2, ref round, winners);
solver.PlayOneRound(p1, p2, ref round, winners);
p1.Should().ContainInOrder(new[] { 6, 3, 1, 9, 5 });
p2.Should().ContainInOrder(new[] { 4, 7, 10, 8, 2 });
round.Should().Be(2);
winners.Should().ContainInOrder(new[] { 1, 2 });
}
[Test]
public void player2_wins()
{
var input = Example();
var solver = Solver();
var (p1, p2) = solver.Parse(input);
solver.Play(p1, p2);
p1.Should().BeEmpty();
p2.Should().ContainInOrder(new[] { 3, 2, 10, 6, 8, 5, 9, 4, 7, 1 });
}
[Test]
public void calculates_result()
{
var player = new[] { 3, 2, 10, 6, 8, 5, 9, 4, 7, 1 };
var solver = Solver();
var result = solver.CalculateResult(player);
result.Should().Be(306);
}
[Test]
public void solves_input()
{
var input = File.ReadAllText("Files\\Day22.txt");
var solver = Solver();
var result = solver.Solve(input);
result.Should().Be(31269);
}
}
}