1
exercism fetch csharp tournament

TournamentTest.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// This file was auto-generated based on version 1.3.0 of the canonical data.

using Xunit;
using System;
using System.IO;
using System.Text;

public class TournamentTest
{
    [Fact]
    public void Just_the_header_if_no_input()
    {
        var input = string.Empty;
        var expected = "Team                           | MP |  W |  D |  L |  P".Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void A_win_is_three_points_a_loss_is_zero_points()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;win".Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  1 |  1 |  0 |  0 |  3" + Environment.NewLine +
                       "Blithering Badgers             |  1 |  0 |  0 |  1 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void A_win_can_also_be_expressed_as_a_loss()
    {
        var input = "Blithering Badgers;Allegoric Alaskans;loss".Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  1 |  1 |  0 |  0 |  3" + Environment.NewLine +
                       "Blithering Badgers             |  1 |  0 |  0 |  1 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void A_different_team_can_win()
    {
        var input = "Blithering Badgers;Allegoric Alaskans;win".Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Blithering Badgers             |  1 |  1 |  0 |  0 |  3" + Environment.NewLine +
                       "Allegoric Alaskans             |  1 |  0 |  0 |  1 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void A_draw_is_one_point_each()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;draw".Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  1 |  0 |  1 |  0 |  1" + Environment.NewLine +
                       "Blithering Badgers             |  1 |  0 |  1 |  0 |  1"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void There_can_be_more_than_one_match()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine +
                       "Allegoric Alaskans;Blithering Badgers;win"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  2 |  2 |  0 |  0 |  6" + Environment.NewLine +
                       "Blithering Badgers             |  2 |  0 |  0 |  2 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void There_can_be_more_than_one_winner()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;loss" + Environment.NewLine +
                       "Allegoric Alaskans;Blithering Badgers;win"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  2 |  1 |  0 |  1 |  3" + Environment.NewLine +
                       "Blithering Badgers             |  2 |  1 |  0 |  1 |  3"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void There_can_be_more_than_two_teams()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine +
                       "Blithering Badgers;Courageous Californians;win" + Environment.NewLine +
                       "Courageous Californians;Allegoric Alaskans;loss"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  2 |  2 |  0 |  0 |  6" + Environment.NewLine +
                       "Blithering Badgers             |  2 |  1 |  0 |  1 |  3" + Environment.NewLine +
                       "Courageous Californians        |  2 |  0 |  0 |  2 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void Typical_input()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine +
                       "Devastating Donkeys;Courageous Californians;draw" + Environment.NewLine +
                       "Devastating Donkeys;Allegoric Alaskans;win" + Environment.NewLine +
                       "Courageous Californians;Blithering Badgers;loss" + Environment.NewLine +
                       "Blithering Badgers;Devastating Donkeys;loss" + Environment.NewLine +
                       "Allegoric Alaskans;Courageous Californians;win"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Devastating Donkeys            |  3 |  2 |  1 |  0 |  7" + Environment.NewLine +
                       "Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6" + Environment.NewLine +
                       "Blithering Badgers             |  3 |  1 |  0 |  2 |  3" + Environment.NewLine +
                       "Courageous Californians        |  3 |  0 |  1 |  2 |  1"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void Incomplete_competition_not_all_pairs_have_played_()
    {
        var input = "Allegoric Alaskans;Blithering Badgers;loss" + Environment.NewLine +
                       "Devastating Donkeys;Allegoric Alaskans;loss" + Environment.NewLine +
                       "Courageous Californians;Blithering Badgers;draw" + Environment.NewLine +
                       "Allegoric Alaskans;Courageous Californians;win"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  3 |  2 |  0 |  1 |  6" + Environment.NewLine +
                       "Blithering Badgers             |  2 |  1 |  1 |  0 |  4" + Environment.NewLine +
                       "Courageous Californians        |  2 |  0 |  1 |  1 |  1" + Environment.NewLine +
                       "Devastating Donkeys            |  1 |  0 |  0 |  1 |  0"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    [Fact(Skip = "Remove to run test")]
    public void Ties_broken_alphabetically()
    {
        var input = "Courageous Californians;Devastating Donkeys;win" + Environment.NewLine +
                       "Allegoric Alaskans;Blithering Badgers;win" + Environment.NewLine +
                       "Devastating Donkeys;Allegoric Alaskans;loss" + Environment.NewLine +
                       "Courageous Californians;Blithering Badgers;win" + Environment.NewLine +
                       "Blithering Badgers;Devastating Donkeys;draw" + Environment.NewLine +
                       "Allegoric Alaskans;Courageous Californians;draw"
                       .Trim();
        var expected = "Team                           | MP |  W |  D |  L |  P" + Environment.NewLine +
                       "Allegoric Alaskans             |  3 |  2 |  1 |  0 |  7" + Environment.NewLine +
                       "Courageous Californians        |  3 |  2 |  1 |  0 |  7" + Environment.NewLine +
                       "Blithering Badgers             |  3 |  0 |  1 |  2 |  1" + Environment.NewLine +
                       "Devastating Donkeys            |  3 |  0 |  1 |  2 |  1"
                       .Trim();
        Assert.Equal(expected, RunTally(input).Trim());
    }

    private string RunTally(string input)
    {
        var encoding = new UTF8Encoding();
        using (var inStream = new MemoryStream(encoding.GetBytes(input)))
        {
            using (var outStream = new MemoryStream())
            {
                Tournament.Tally(inStream, outStream);
                return encoding.GetString(outStream.ToArray());
            }
        }
    }
}