|
| 1 | +module main |
| 2 | + |
| 3 | +fn test_just_the_header_if_no_input() { |
| 4 | + rows := '' |
| 5 | + expected := ('Team | MP | W | D | L | P') |
| 6 | + assert tally(rows) == expected |
| 7 | +} |
| 8 | + |
| 9 | +fn test_a_win_is_three_points_a_loss_is_zero_points() { |
| 10 | + rows := ('Allegoric Alaskans;Blithering Badgers;win') |
| 11 | + expected := ('Team | MP | W | D | L | P |
| 12 | +Allegoric Alaskans | 1 | 1 | 0 | 0 | 3 |
| 13 | +Blithering Badgers | 1 | 0 | 0 | 1 | 0') |
| 14 | + assert tally(rows) == expected |
| 15 | +} |
| 16 | + |
| 17 | +fn test_a_win_can_also_be_expressed_as_a_loss() { |
| 18 | + rows := ('Blithering Badgers;Allegoric Alaskans;loss') |
| 19 | + expected := ('Team | MP | W | D | L | P |
| 20 | +Allegoric Alaskans | 1 | 1 | 0 | 0 | 3 |
| 21 | +Blithering Badgers | 1 | 0 | 0 | 1 | 0') |
| 22 | + assert tally(rows) == expected |
| 23 | +} |
| 24 | + |
| 25 | +fn test_a_different_team_can_win() { |
| 26 | + rows := ('Blithering Badgers;Allegoric Alaskans;win') |
| 27 | + expected := ('Team | MP | W | D | L | P |
| 28 | +Blithering Badgers | 1 | 1 | 0 | 0 | 3 |
| 29 | +Allegoric Alaskans | 1 | 0 | 0 | 1 | 0') |
| 30 | + assert tally(rows) == expected |
| 31 | +} |
| 32 | + |
| 33 | +fn test_a_draw_is_one_point_each() { |
| 34 | + rows := ('Allegoric Alaskans;Blithering Badgers;draw') |
| 35 | + expected := ('Team | MP | W | D | L | P |
| 36 | +Allegoric Alaskans | 1 | 0 | 1 | 0 | 1 |
| 37 | +Blithering Badgers | 1 | 0 | 1 | 0 | 1') |
| 38 | + assert tally(rows) == expected |
| 39 | +} |
| 40 | + |
| 41 | +fn test_there_can_be_more_than_one_match() { |
| 42 | + rows := ('Allegoric Alaskans;Blithering Badgers;win |
| 43 | +Allegoric Alaskans;Blithering Badgers;win') |
| 44 | + expected := ('Team | MP | W | D | L | P |
| 45 | +Allegoric Alaskans | 2 | 2 | 0 | 0 | 6 |
| 46 | +Blithering Badgers | 2 | 0 | 0 | 2 | 0') |
| 47 | + assert tally(rows) == expected |
| 48 | +} |
| 49 | + |
| 50 | +fn test_there_can_be_more_than_one_winner() { |
| 51 | + rows := ('Allegoric Alaskans;Blithering Badgers;loss |
| 52 | +Allegoric Alaskans;Blithering Badgers;win') |
| 53 | + expected := ('Team | MP | W | D | L | P |
| 54 | +Allegoric Alaskans | 2 | 1 | 0 | 1 | 3 |
| 55 | +Blithering Badgers | 2 | 1 | 0 | 1 | 3') |
| 56 | + assert tally(rows) == expected |
| 57 | +} |
| 58 | + |
| 59 | +fn test_there_can_be_more_than_two_teams() { |
| 60 | + rows := ('Allegoric Alaskans;Blithering Badgers;win |
| 61 | +Blithering Badgers;Courageous Californians;win |
| 62 | +Courageous Californians;Allegoric Alaskans;loss') |
| 63 | + expected := ('Team | MP | W | D | L | P |
| 64 | +Allegoric Alaskans | 2 | 2 | 0 | 0 | 6 |
| 65 | +Blithering Badgers | 2 | 1 | 0 | 1 | 3 |
| 66 | +Courageous Californians | 2 | 0 | 0 | 2 | 0') |
| 67 | + assert tally(rows) == expected |
| 68 | +} |
| 69 | + |
| 70 | +fn test_typical_input() { |
| 71 | + rows := ('Allegoric Alaskans;Blithering Badgers;win |
| 72 | +Devastating Donkeys;Courageous Californians;draw |
| 73 | +Devastating Donkeys;Allegoric Alaskans;win |
| 74 | +Courageous Californians;Blithering Badgers;loss |
| 75 | +Blithering Badgers;Devastating Donkeys;loss |
| 76 | +Allegoric Alaskans;Courageous Californians;win') |
| 77 | + expected := ('Team | MP | W | D | L | P |
| 78 | +Devastating Donkeys | 3 | 2 | 1 | 0 | 7 |
| 79 | +Allegoric Alaskans | 3 | 2 | 0 | 1 | 6 |
| 80 | +Blithering Badgers | 3 | 1 | 0 | 2 | 3 |
| 81 | +Courageous Californians | 3 | 0 | 1 | 2 | 1') |
| 82 | + assert tally(rows) == expected |
| 83 | +} |
| 84 | + |
| 85 | +fn test_incomplete_competition_not_all_pairs_have_played() { |
| 86 | + rows := ('Allegoric Alaskans;Blithering Badgers;loss |
| 87 | +Devastating Donkeys;Allegoric Alaskans;loss |
| 88 | +Courageous Californians;Blithering Badgers;draw |
| 89 | +Allegoric Alaskans;Courageous Californians;win') |
| 90 | + expected := ('Team | MP | W | D | L | P |
| 91 | +Allegoric Alaskans | 3 | 2 | 0 | 1 | 6 |
| 92 | +Blithering Badgers | 2 | 1 | 1 | 0 | 4 |
| 93 | +Courageous Californians | 2 | 0 | 1 | 1 | 1 |
| 94 | +Devastating Donkeys | 1 | 0 | 0 | 1 | 0') |
| 95 | + assert tally(rows) == expected |
| 96 | +} |
| 97 | + |
| 98 | +fn test_ties_broken_alphabetically() { |
| 99 | + rows := ('Courageous Californians;Devastating Donkeys;win |
| 100 | +Allegoric Alaskans;Blithering Badgers;win |
| 101 | +Devastating Donkeys;Allegoric Alaskans;loss |
| 102 | +Courageous Californians;Blithering Badgers;win |
| 103 | +Blithering Badgers;Devastating Donkeys;draw |
| 104 | +Allegoric Alaskans;Courageous Californians;draw') |
| 105 | + expected := ('Team | MP | W | D | L | P |
| 106 | +Allegoric Alaskans | 3 | 2 | 1 | 0 | 7 |
| 107 | +Courageous Californians | 3 | 2 | 1 | 0 | 7 |
| 108 | +Blithering Badgers | 3 | 0 | 1 | 2 | 1 |
| 109 | +Devastating Donkeys | 3 | 0 | 1 | 2 | 1') |
| 110 | + assert tally(rows) == expected |
| 111 | +} |
| 112 | + |
| 113 | +fn test_ensure_points_sorted_numerically() { |
| 114 | + rows := ('Devastating Donkeys;Blithering Badgers;win |
| 115 | +Devastating Donkeys;Blithering Badgers;win |
| 116 | +Devastating Donkeys;Blithering Badgers;win |
| 117 | +Devastating Donkeys;Blithering Badgers;win |
| 118 | +Blithering Badgers;Devastating Donkeys;win') |
| 119 | + expected := ('Team | MP | W | D | L | P |
| 120 | +Devastating Donkeys | 5 | 4 | 0 | 1 | 12 |
| 121 | +Blithering Badgers | 5 | 1 | 0 | 4 | 3') |
| 122 | + assert tally(rows) == expected |
| 123 | +} |
0 commit comments