Skip to content

Commit d68b7d6

Browse files
bird-watch: change Task 6 in order to respect pattern matching more (#1007)
bird-watch: change Task 6 in order to respect pattern matching more Co-authored-by: Erik Schierboom <[email protected]>
1 parent 6ea7072 commit d68b7d6

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

exercises/concept/bird-watcher/.docs/instructions.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ incrementTodaysCount birdCount
5252

5353
## 6. Check for odd week
5454

55-
Over the last year, you've found that some weeks for the same, odd pattern, where the counts alternate between one and zero birds visiting. Implement the `oddWeek` function that returns `true` if the bird count pattern of this week matches the odd pattern:
55+
Over the last year, you've found that some weeks have the same, odd patterns:
56+
- On each even day of the week, there were no birds
57+
- On each even day of the week, exactly 10 birds were spotted
58+
- On each odd day of the week, exactly 5 birds were spotted
59+
60+
Implement the `oddWeek` function that returns `true` if the bird count pattern of this week matches one of the odd patterns:
5661

5762
```fsharp
58-
oddWeek [| 1; 0; 1; 0; 1; 0; 1 |]
63+
oddWeek [| 1; 0; 5; 0; 12; 0; 2 |]
64+
// => true
65+
66+
oddWeek [| 5; 0; 5; 12; 5; 3; 5|]
5967
// => true
6068
```
6169

exercises/concept/bird-watcher/.meta/Exemplar.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ let incrementTodaysCount (counts: int []): int [] =
1414

1515
let oddWeek (counts: int []) =
1616
match counts with
17-
| [| 1; 0; 1; 0; 1; 0; 1 |] -> true
17+
| [| _; 0; _; 0; _; 0; _ |]
18+
| [| _; 10; _; 10; _; 10; _ |]
19+
| [| 5; _; 5; _; 5; _; 5|] -> true
1820
| _ -> false

exercises/concept/bird-watcher/BirdWatcherTests.fs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Xunit
55
open Exercism.Tests
66

77
open BirdWatcher
8+
open System
89

910
[<Fact>]
1011
[<Task(1)>]
@@ -62,12 +63,60 @@ let ``Increment today's count with multiple previous visits`` () =
6263

6364
[<Fact>]
6465
[<Task(6)>]
65-
let ``Odd week for week matching odd pattern`` () =
66-
oddWeek [| 1; 0; 1; 0; 1; 0; 1 |]
66+
let ``Odd week for first week matching odd days zero pattern`` () =
67+
oddWeek [| 1; 0; 2; 0; 3; 0; 4 |]
6768
|> should equal true
6869

6970
[<Fact>]
7071
[<Task(6)>]
71-
let `` Odd week for week that does not match odd pattern`` () =
72+
let ``Odd week for second week matching odd days zero pattern`` () =
73+
oddWeek [| 10; 0; 6; 0; 9; 0; 4 |]
74+
|> should equal true
75+
76+
[<Fact>]
77+
[<Task(6)>]
78+
let ``Odd week for first week matching odd days ten pattern`` () =
79+
oddWeek [| 6; 10; 2; 10; 5; 10; 8 |]
80+
|> should equal true
81+
82+
[<Fact>]
83+
[<Task(6)>]
84+
let ``Odd week for second week matching odd days ten pattern`` () =
85+
oddWeek [| 16; 10; 8; 10; 4; 10; 7 |]
86+
|> should equal true
87+
88+
[<Fact>]
89+
[<Task(6)>]
90+
let ``Odd week for first week matching even days five pattern`` () =
91+
oddWeek [| 5; 1; 5; 2; 5; 3; 5 |]
92+
|> should equal true
93+
94+
[<Fact>]
95+
[<Task(6)>]
96+
let ``Odd week for second week matching even days five pattern`` () =
97+
oddWeek [| 5; 12; 5; 6; 5; 5; 5 |]
98+
|> should equal true
99+
100+
[<Fact>]
101+
[<Task(6)>]
102+
let ``Odd week for first week that does not match odd pattern`` () =
72103
oddWeek [| 2; 2; 1; 0; 1; 1; 1 |]
73104
|> should equal false
105+
106+
[<Fact>]
107+
[<Task(6)>]
108+
let ``Odd week for second week that does not match odd pattern`` () =
109+
oddWeek [| 2; 0; 1; 1; 1; 0; 1 |]
110+
|> should equal false
111+
112+
[<Fact>]
113+
[<Task(6)>]
114+
let ``Odd week for third week that does not match odd pattern`` () =
115+
oddWeek [| 2; 0; 1; 10; 1; 10; 1 |]
116+
|> should equal false
117+
118+
[<Fact>]
119+
[<Task(6)>]
120+
let ``Odd week for fourth week that does not match odd pattern`` () =
121+
oddWeek [| 5; 0; 5; 1; 1; 0; 5 |]
122+
|> should equal false

0 commit comments

Comments
 (0)