< Summary

Class:MineSweeper.MineField
Assembly:MineSweeper
File(s):/home/runner/work/KATA-MineSweeper-20210502b/KATA-MineSweeper-20210502b/src/MineSweeper/MineField.cs
Covered lines:20
Uncovered lines:0
Coverable lines:20
Total lines:44
Line coverage:100% (20 of 20)
Covered branches:12
Total branches:16
Branch coverage:75% (12 of 16)
Tag:52_817390446

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%110100%
.ctor(...)0%110100%
GetCell(...)84.62%7.7776475%
Click(...)66.67%222100%

File(s)

/home/runner/work/KATA-MineSweeper-20210502b/KATA-MineSweeper-20210502b/src/MineSweeper/MineField.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.Runtime.CompilerServices;
 4using static MineSweeper.MineFieldHelper;
 5
 6[assembly: InternalsVisibleTo("MineSweeper.Tests")]
 7
 8namespace MineSweeper
 9{
 10    public class MineField
 11    {
 12        public MineField(int width, int height, int bombsCount = 0) :
 213            this(width, height, RandomIndexGenerator(width, height).Distinct()
 214                                                                   .Take(bombsCount))
 415        { }
 16
 417        public MineField(int width, int height, IEnumerable<(int X, int Y)> bombPosGenerator)
 418        {
 419            Width = width;
 420            Height = height;
 21
 422            Cells = (from x in Enumerable.Range(0, width)
 1623                     from y in Enumerable.Range(0, height)
 4024                     select new Cell(NearCellGenerator(x, y, GetCell)))
 425                    .ToList();
 26
 927            bombPosGenerator.ForEach(x => GetCell(x)?.SetBomb());
 428        }
 29
 30        internal IList<Cell> Cells { get; }
 31        public int Width { get; }
 32        public int Height { get; }
 33
 8634        public Cell GetCell((int X, int Y) pos) => pos switch
 8635        {
 19636            (var x, _) when x < 0 || x >= Width => null,
 16837            (_, var y) when y < 0 || y >= Height => null,
 12838            _ => Cells[(pos.Y * Width) + pos.X]
 8639        };
 40
 41        public void Click(int x, int y) =>
 142            GetCell((x, y))?.Click();
 43    }
 44}