< Summary

Information
Class: Minesweeper.MinefieldModule
Assembly: Minesweeper
File(s): /home/runner/work/kata-fsharp-tdd-minesweeper3/kata-fsharp-tdd-minesweeper3/src/Minesweeper/Minefield.fs
Tag: 37_3611326257
Line coverage
90%
Covered lines: 30
Uncovered lines: 3
Coverable lines: 33
Total lines: 61
Line coverage: 90.9%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Coverage History

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
start(...)75%492.85%
Invoke(...)100%1100%
GenerateNext(...)90%10100%
string(...)50%485.71%
cells(...)50%250%

File(s)

/home/runner/work/kata-fsharp-tdd-minesweeper3/kata-fsharp-tdd-minesweeper3/src/Minesweeper/Minefield.fs

#LineLine coverage
 1namespace Minesweeper
 2
 3open System.Text
 4open FSharpPlus
 5open Cell
 6
 7
 8type Width = int
 9type Height = int
 10type Cells = Map<(int*int), Cell>
 11type BombsPos = seq<(int*int)>
 12
 13type Minefield =
 14    | Setup of Width * Height
 15    | SetupWithBombs of Width * Height * BombsPos
 16    | Playing of Width * Height * Cells
 17
 18module Minefield =
 19    let rec start v =
 420        match v with
 21        | SetupWithBombs (w, h, z) ->
 422            let nearBombsPos (y, x) = seq {
 423                (y - 1, x - 1) ;
 424                (y - 1, x);
 425                (y - 1, x + 1);
 426                (y    , x - 1) ;
 427                (y    , x + 1);
 428                (y + 1, x - 1) ;
 429                (y + 1, x);
 430                (y + 1, x + 1);
 431            }
 332            let cells = Map.ofSeq <| seq {
 1533                for y in {0..h - 1} do
 6334                for x in {0..w - 1} do
 3635                yield ((y, x), init)
 336            }
 37            let cellsWithBombs =
 938                (cells, z) ||> Seq.fold (fun s p ->
 1939                    s |> Map.change p (Option.map (fun _ -> Bomb |> Covered)))
 40            let cellsWithBombsAndNumber =
 941                (cellsWithBombs, z) ||> Seq.fold (fun s p ->
 1242                    (s, nearBombsPos(p)) ||> Seq.fold(fun s1 p1 ->
 7143                        s1 |> Map.change p1 (Option.map add)))
 344            Playing (w, h, cellsWithBombsAndNumber)
 245        | Setup (w, h) -> SetupWithBombs (w, h, Seq.empty) |> start
 046        | _ -> v
 47    let string v (f : Cell -> char) =
 248        match v with
 49        | Playing (w, h, z) ->
 1050            (StringBuilder(), z |> Map.toSeq) ||> fold (fun s ((y, x), c) ->
 7251                let _1 = s.Append (c |> f)
 2452                match x with
 3053                | _ when x = w - 1 -> _1.Append '\n'
 2254                | _ -> _1.Append ' ') |> string
 055        | _ -> ""
 56    let cells = function
 157        | Playing (w, h, z) -> z
 058        | _ -> Map.empty
 59
 60
 61