< Summary

Information
Class: BallSort.Engine.Infrastructure.PuzzleManager
Assembly: BallSort.Engine
File(s): /home/runner/work/BallSort/BallSort/src/BallSort.Engine/Infrastructure/PuzzleManager.cs
Tag: 216
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 43
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_PuzzleCount()100%11100%
GetPuzzle(...)100%11100%
.ctor(...)100%44100%

File(s)

/home/runner/work/BallSort/BallSort/src/BallSort.Engine/Infrastructure/PuzzleManager.cs

#LineLine coverage
 1using System.Collections.Immutable;
 2using System.Text.Json;
 3using BallSort.Engine.Game;
 4using BallSort.Engine.Models;
 5
 6namespace BallSort.Engine.Infrastructure;
 7
 8public class PuzzleManager
 9{
 10    private readonly ImmutableArray<Board> _puzzles;
 11
 212    private static readonly JsonSerializerOptions JsonSerializerOptions = new()
 213    {
 214        PropertyNameCaseInsensitive = true
 215    };
 16
 2617    public int PuzzleCount => _puzzles.Length;
 18
 2619    public Board GetPuzzle(int puzzleNumber) => _puzzles[puzzleNumber].Clone();
 20
 621    public PuzzleManager(string path)
 22    {
 623        if (string.IsNullOrWhiteSpace(path))
 24        {
 225            throw new InvalidOperationException("Please pass in a valid path.");
 26        }
 27
 428        var puzzleJson = File.ReadAllText(path);
 29
 430        var puzzles = JsonSerializer.Deserialize<Puzzle[]>(puzzleJson, JsonSerializerOptions);
 31
 432        var builder = ImmutableArray.CreateBuilder<Board>(puzzles.Length);
 33
 10434        foreach (var puzzle in puzzles)
 35        {
 4836            var board = new Board(puzzle);
 37
 4838            builder.Add(board);
 39        }
 40
 441        _puzzles = builder.ToImmutable();
 442    }
 43}