< Summary

Information
Class: SwiftCollections.Dimensions.SwiftBoolArray2D
Assembly: SwiftCollections
File(s): /home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftBoolArray2D.cs
Line coverage
92%
Covered lines: 24
Uncovered lines: 2
Coverable lines: 26
Total lines: 73
Line coverage: 92.3%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%210%
.ctor(...)100%11100%
Toggle(...)100%11100%
SetRegion(...)100%66100%
CountTrue()100%44100%

File(s)

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Dimension/Default/SwiftBoolArray2D.cs

#LineLine coverage
 1using MemoryPack;
 2using System;
 3using System.Text.Json.Serialization;
 4
 5namespace SwiftCollections.Dimensions;
 6
 7/// <summary>
 8/// Represents a 2D array specifically designed to handle boolean values.
 9/// </summary>
 10[Serializable]
 11[JsonConverter(typeof(SwiftStateJsonConverterFactory))]
 12[MemoryPackable]
 13public partial class SwiftBoolArray2D : SwiftArray2D<bool>
 14{
 15    #region Constructors
 16
 017    public SwiftBoolArray2D() { }
 18
 619    public SwiftBoolArray2D(int width, int height) : base(width, height) { }
 20
 1821    public SwiftBoolArray2D(int width, int height, bool defaultValue) : base(width, height, defaultValue) { }
 22
 023    public SwiftBoolArray2D(bool[,] source) : base(source) { }
 24
 25    [MemoryPackConstructor]
 626    public SwiftBoolArray2D(Array2DState<bool> state) : base(state) { }
 27
 28    #endregion
 29
 30    #region Collection Management
 31
 32    /// <summary>
 33    /// Toggles the value at the specified position in the array.
 34    /// </summary>
 35    public void Toggle(int x, int y)
 100000236    {
 100000237        this[x, y] = !this[x, y];
 100000238    }
 39
 40    /// <summary>
 41    /// Sets all values within a rectangular region to the specified value.
 42    /// </summary>
 43    public void SetRegion(int xStart, int yStart, int width, int height, bool value)
 344    {
 2845        for (int x = xStart; x < xStart + width; x++)
 1146        {
 10847            for (int y = yStart; y < yStart + height; y++)
 4348            {
 4349                if (IsValidIndex(x, y))
 2250                    this[x, y] = value;
 4351            }
 1152        }
 353    }
 54
 55    #endregion
 56
 57    #region Utility Methods
 58
 59    /// <summary>
 60    /// Counts the number of true values in the array.
 61    /// </summary>
 62    public int CountTrue()
 563    {
 564        int count = 0;
 200019765        foreach (var cell in InnerArray)
 100009166        {
 200011567            if (cell) count++;
 100009168        }
 569        return count;
 570    }
 71
 72    #endregion
 73}