Skip to content

Commit

Permalink
killer-sudoku-helper: fix generator (#1297)
Browse files Browse the repository at this point in the history
* bottle-song: fix generator

* resistor-color-trio: fix generator

* knapsack: fix generator

* killer-sudoku-helper: fix generator

* state-of-tic-tac-toe: fix generator
  • Loading branch information
ErikSchierboom authored Oct 22, 2024
1 parent bd2adae commit 2637a60
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 507 deletions.
198 changes: 96 additions & 102 deletions exercises/practice/bottle-song/BottleSongTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,130 +7,124 @@ open BottleSong

[<Fact>]
let ``First generic verse`` () =
recite 10 1
|> should
equal
[ "Ten green bottles hanging on the wall,"
"Ten green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Ten green bottles hanging on the wall,";
"Ten green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be nine green bottles hanging on the wall." ]
recite 10 1 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Last generic verse`` () =
recite 3 1
|> should
equal
[ "Three green bottles hanging on the wall,"
"Three green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Three green bottles hanging on the wall,";
"Three green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be two green bottles hanging on the wall." ]
recite 3 1 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Verse with 2 bottles`` () =
recite 2 1
|> should
equal
[ "Two green bottles hanging on the wall,"
"Two green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Two green bottles hanging on the wall,";
"Two green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be one green bottle hanging on the wall." ]
recite 2 1 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Verse with 1 bottle`` () =
recite 1 1
|> should
equal
[ "One green bottle hanging on the wall,"
"One green bottle hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "One green bottle hanging on the wall,";
"One green bottle hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be no green bottles hanging on the wall." ]
recite 1 1 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``First two verses`` () =
recite 10 2
|> should
equal
[ "Ten green bottles hanging on the wall,"
"Ten green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be nine green bottles hanging on the wall."
""
"Nine green bottles hanging on the wall,"
"Nine green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Ten green bottles hanging on the wall,";
"Ten green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be nine green bottles hanging on the wall.";
"";
"Nine green bottles hanging on the wall,";
"Nine green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be eight green bottles hanging on the wall." ]
recite 10 2 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Last three verses`` () =
recite 3 3
|> should
equal
[ "Three green bottles hanging on the wall,"
"Three green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be two green bottles hanging on the wall."
""
"Two green bottles hanging on the wall,"
"Two green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be one green bottle hanging on the wall."
""
"One green bottle hanging on the wall,"
"One green bottle hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Three green bottles hanging on the wall,";
"Three green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be two green bottles hanging on the wall.";
"";
"Two green bottles hanging on the wall,";
"Two green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be one green bottle hanging on the wall.";
"";
"One green bottle hanging on the wall,";
"One green bottle hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be no green bottles hanging on the wall." ]
recite 3 3 |> should equal expected

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``All verses`` () =
recite 10 10
|> should
equal
[ "Ten green bottles hanging on the wall,"
"Ten green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be nine green bottles hanging on the wall."
""
"Nine green bottles hanging on the wall,"
"Nine green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be eight green bottles hanging on the wall."
""
"Eight green bottles hanging on the wall,"
"Eight green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be seven green bottles hanging on the wall."
""
"Seven green bottles hanging on the wall,"
"Seven green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be six green bottles hanging on the wall."
""
"Six green bottles hanging on the wall,"
"Six green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be five green bottles hanging on the wall."
""
"Five green bottles hanging on the wall,"
"Five green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be four green bottles hanging on the wall."
""
"Four green bottles hanging on the wall,"
"Four green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be three green bottles hanging on the wall."
""
"Three green bottles hanging on the wall,"
"Three green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be two green bottles hanging on the wall."
""
"Two green bottles hanging on the wall,"
"Two green bottles hanging on the wall,"
"And if one green bottle should accidentally fall,"
"There'll be one green bottle hanging on the wall."
""
"One green bottle hanging on the wall,"
"One green bottle hanging on the wall,"
"And if one green bottle should accidentally fall,"
let expected =
[ "Ten green bottles hanging on the wall,";
"Ten green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be nine green bottles hanging on the wall.";
"";
"Nine green bottles hanging on the wall,";
"Nine green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be eight green bottles hanging on the wall.";
"";
"Eight green bottles hanging on the wall,";
"Eight green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be seven green bottles hanging on the wall.";
"";
"Seven green bottles hanging on the wall,";
"Seven green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be six green bottles hanging on the wall.";
"";
"Six green bottles hanging on the wall,";
"Six green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be five green bottles hanging on the wall.";
"";
"Five green bottles hanging on the wall,";
"Five green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be four green bottles hanging on the wall.";
"";
"Four green bottles hanging on the wall,";
"Four green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be three green bottles hanging on the wall.";
"";
"Three green bottles hanging on the wall,";
"Three green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be two green bottles hanging on the wall.";
"";
"Two green bottles hanging on the wall,";
"Two green bottles hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be one green bottle hanging on the wall.";
"";
"One green bottle hanging on the wall,";
"One green bottle hanging on the wall,";
"And if one green bottle should accidentally fall,";
"There'll be no green bottles hanging on the wall." ]
recite 10 10 |> should equal expected

2 changes: 1 addition & 1 deletion exercises/practice/killer-sudoku-helper/.meta/Example.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module List =
List.map ((@) [ x ]) (combinations (k - 1) xs)
@ combinations k xs

let combinations sum size exclude =
let combinations exclude size sum =
[ 1..9 ]
|> List.except exclude
|> List.combinations size
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module KillerSudokuHelper

let combinations sum size exclude =
let combinations exclude size sum =
failwith "Please implement the 'combinations' function"
36 changes: 14 additions & 22 deletions exercises/practice/killer-sudoku-helper/KillerSudokuHelperTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,53 @@ open KillerSudokuHelper

[<Fact>]
let ``1`` () =
combinations 1 1 [] |> should equal [ [ 1 ] ]
combinations [] 1 1 |> should equal [[1]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``2`` () =
combinations 2 1 [] |> should equal [ [ 2 ] ]
combinations [] 1 2 |> should equal [[2]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``3`` () =
combinations 3 1 [] |> should equal [ [ 3 ] ]
combinations [] 1 3 |> should equal [[3]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``4`` () =
combinations 4 1 [] |> should equal [ [ 4 ] ]
combinations [] 1 4 |> should equal [[4]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``5`` () =
combinations 5 1 [] |> should equal [ [ 5 ] ]
combinations [] 1 5 |> should equal [[5]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``6`` () =
combinations 6 1 [] |> should equal [ [ 6 ] ]
combinations [] 1 6 |> should equal [[6]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``7`` () =
combinations 7 1 [] |> should equal [ [ 7 ] ]
combinations [] 1 7 |> should equal [[7]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``8`` () =
combinations 8 1 [] |> should equal [ [ 8 ] ]
combinations [] 1 8 |> should equal [[8]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``9`` () =
combinations 9 1 [] |> should equal [ [ 9 ] ]
combinations [] 1 9 |> should equal [[9]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Cage with sum 45 contains all digits 1:9`` () =
combinations 45 9 []
|> should equal [ [ 1; 2; 3; 4; 5; 6; 7; 8; 9 ] ]
combinations [] 9 45 |> should equal [[1; 2; 3; 4; 5; 6; 7; 8; 9]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Cage with only 1 possible combination`` () =
combinations 7 3 []
|> should equal [ [ 1; 2; 4 ] ]
combinations [] 3 7 |> should equal [[1; 2; 4]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Cage with several combinations`` () =
combinations 10 2 []
|> should
equal
[ [ 1; 9 ]
[ 2; 8 ]
[ 3; 7 ]
[ 4; 6 ] ]
combinations [] 2 10 |> should equal [[1; 9]; [2; 8]; [3; 7]; [4; 6]]

[<Fact(Skip = "Remove this Skip property to run this test")>]
let ``Cage with several combinations that is restricted`` () =
combinations 10 2 [ 1; 4 ]
|> should equal [ [ 2; 8 ]; [ 3; 7 ] ]
combinations [1; 4] 2 10 |> should equal [[2; 8]; [3; 7]]

Loading

0 comments on commit 2637a60

Please sign in to comment.