< Summary

Class:Minesweeper.MineField
Assembly:Minesweeper
File(s):/home/runner/work/KATA-Minesweeper-20210527/KATA-Minesweeper-20210527/src/Minesweeper/MineField.cs
Covered lines:60
Uncovered lines:0
Coverable lines:60
Total lines:92
Line coverage:100% (60 of 60)
Covered branches:21
Total branches:24
Branch coverage:87.5% (21 of 24)
Tag:28_1324931658

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%110100%
GenerateBombs(...)80%444100%
RandomGenerator()0%330100%
CalculatedNearBombsCount()100%668100%
NearCellGenerator(...)100%222100%
>c__DisplayClass14_0/<<NearCellGenerator()0%11110100%
NearCellGenerator(...)0%110100%
Click(...)0%110100%
GetCell(...)84.62%7.2376483.33%

File(s)

/home/runner/work/KATA-Minesweeper-20210527/KATA-Minesweeper-20210527/src/Minesweeper/MineField.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.Security.Cryptography;
 4
 5namespace Minesweeper
 6{
 7    public class MineField
 8    {
 49        public MineField(int width, int height)
 410        {
 411            Width = width;
 412            Height = height;
 13
 414            Cells = (from y in Enumerable.Range(0, Height)
 1615                     from x in Enumerable.Range(0, Width)
 4016                     select new Cell((x, y), NearCellGenerator(x, y)))
 417                    .ToList();
 418        }
 19
 20        public IList<Cell> Cells { get; set; }
 21
 22        public int Width { get; }
 23        public int Height { get; }
 24
 25        public void GenerateBombs(int countBombs)
 126        {
 927            foreach (var idx in (from idx in RandomGenerator()
 428                                 select idx).Distinct().Take(countBombs))
 329            {
 330                Cells[idx].SetBomb();
 331            }
 132        }
 33
 34        public IEnumerable<int> RandomGenerator()
 135        {
 336            while (true)
 337            {
 338                yield return RandomNumberGenerator.GetInt32(Width * Height);
 239            }
 40        }
 41
 42        public void CalculatedNearBombsCount()
 243        {
 1244            foreach(var cell in from cell in Cells
 2045                                where cell.IsBomb
 246                                select cell)
 347            {
 2748                foreach(var nearcell in NearCellGenerator(cell))
 949                {
 950                    nearcell.NearBombsCount++;
 951                }
 352            }
 253        }
 54
 55        private IEnumerable<Cell> NearCellGenerator(int x, int y)
 3956        {
 10357            return InternalNearCellCenerator().Where(x => x is not null);
 58
 59            IEnumerable<Cell> InternalNearCellCenerator()
 860            {
 861                yield return GetCell(x - 1, y - 1);
 862                yield return GetCell(x, y - 1);
 863                yield return GetCell(x + 1, y - 1);
 864                yield return GetCell(x - 1, y);
 865                yield return GetCell(x + 1, y);
 866                yield return GetCell(x - 1, y + 1);
 867                yield return GetCell(x, y + 1);
 868                yield return GetCell(x + 1, y + 1);
 869            }
 3970        }
 71
 72        private IEnumerable<Cell> NearCellGenerator(Cell cell)
 373        {
 374            var (x, y) = cell.XY;
 75
 376            return NearCellGenerator(x, y);
 377        }
 78
 79        public void Click(int x, int y)
 180        {
 181            GetCell(x, y).Click();
 182        }
 6583        private Cell GetCell(int x, int y) => (x, y) switch
 6584        {
 13985            (var a, _) when a < 0 => null,
 13386            (var a, _) when a >= Width => null,
 11787            (_, var b) when b < 0 => null,
 10888            (_, var b) when b >= Height => null,
 9489            (var a, var b) => Cells[a + b * Width],
 6590        };
 91    }
 92}