< Summary

Class:GDX.Developer.Reports.Resource.IntegerDiff
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/IntegerDiff.cs
Covered lines:23
Uncovered lines:13
Coverable lines:36
Total lines:79
Line coverage:63.8% (23 of 36)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:4
Method coverage:100% (4 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
IntegerDiff(...)0%2.062075%
GetOutput(...)0%7.195055.56%
GetBeforeAndAfterOutput()0%110100%
OptionalPercentageOutput()0%64050%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/IntegerDiff.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5#if !UNITY_DOTSRUNTIME
 6
 7namespace GDX.Developer.Reports.Resource
 8{
 9    [HideFromDocFX]
 10    public readonly struct IntegerDiff
 11    {
 12        public readonly float Percentage;
 13        public readonly int Change;
 14        public readonly int LeftHandSide;
 15        public readonly int RightHandSide;
 16
 17        public IntegerDiff(int lhs, int rhs)
 118        {
 119            LeftHandSide = lhs;
 120            RightHandSide = rhs;
 21
 22
 123            Change = rhs - lhs;
 124            if (lhs == 0)
 025            {
 026                Percentage = Change;
 027            }
 28            else
 129            {
 130                Percentage = 100f * ((float)Change / lhs);
 131            }
 132        }
 33
 34        public string GetOutput(ResourceReportContext context, bool fullWidth = false)
 135        {
 136            if (Change == 0)
 037            {
 038                return GetBeforeAndAfterOutput();
 39            }
 40
 41            // We dont have an idea of the width
 142            if (fullWidth || context == null)
 043            {
 044                return LeftHandSide == 0
 45                    ? $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString()}"
 46                    : $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString(),-12} {Opti
 47            }
 48
 149            return
 50                $"{GetBeforeAndAfterOutput().PadRight(context.KeyValuePairInfoWidth)} {ResourceReport.PositiveSign(Chang
 151        }
 52
 53        string GetBeforeAndAfterOutput()
 154        {
 155            return $"{LeftHandSide.ToString()} => {RightHandSide.ToString()}";
 156        }
 57
 58        string OptionalPercentageOutput()
 159        {
 160            if (LeftHandSide == 0)
 061            {
 062                return null;
 63            }
 64
 165            if (Percentage > 0)
 166            {
 167                return $" +{UnityEngine.Mathf.RoundToInt(Percentage).ToString()}%";
 68            }
 69
 070            if (Percentage < 0)
 071            {
 072                return $" {UnityEngine.Mathf.RoundToInt(Percentage).ToString()}%";
 73            }
 74
 075            return null;
 176        }
 77    }
 78}
 79#endif