< Summary

Class:GDX.Developer.Reports.Resource.IntegerDiff
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/IntegerDiff.cs
Covered lines:23
Uncovered lines:13
Coverable lines:36
Total lines:81
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)

./Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/IntegerDiff.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 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
 5using UnityEngine;
 6
 7#if !UNITY_DOTSRUNTIME
 8
 9namespace GDX.Developer.Reports.Resource
 10{
 11    [HideFromDocFX]
 12    public readonly struct IntegerDiff
 13    {
 14        public readonly float Percentage;
 15        public readonly int Change;
 16        public readonly int LeftHandSide;
 17        public readonly int RightHandSide;
 18
 19        public IntegerDiff(int lhs, int rhs)
 120        {
 121            LeftHandSide = lhs;
 122            RightHandSide = rhs;
 23
 24
 125            Change = rhs - lhs;
 126            if (lhs == 0)
 027            {
 028                Percentage = Change;
 029            }
 30            else
 131            {
 132                Percentage = 100f * ((float)Change / lhs);
 133            }
 134        }
 35
 36        public string GetOutput(ResourceReportContext context, bool fullWidth = false)
 137        {
 138            if (Change == 0)
 039            {
 040                return GetBeforeAndAfterOutput();
 41            }
 42
 43            // We dont have an idea of the width
 144            if (fullWidth || context == null)
 045            {
 046                return LeftHandSide == 0
 47                    ? $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString()}"
 48                    : $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString(),-12} {Opti
 49            }
 50
 151            return
 52                $"{GetBeforeAndAfterOutput().PadRight(context.KeyValuePairInfoWidth)} {ResourceReport.PositiveSign(Chang
 153        }
 54
 55        string GetBeforeAndAfterOutput()
 156        {
 157            return $"{LeftHandSide.ToString()} => {RightHandSide.ToString()}";
 158        }
 59
 60        string OptionalPercentageOutput()
 161        {
 162            if (LeftHandSide == 0)
 063            {
 064                return null;
 65            }
 66
 167            if (Percentage > 0)
 168            {
 169                return $" +{Mathf.RoundToInt(Percentage).ToString()}%";
 70            }
 71
 072            if (Percentage < 0)
 073            {
 074                return $" {Mathf.RoundToInt(Percentage).ToString()}%";
 75            }
 76
 077            return null;
 178        }
 79    }
 80}
 81#endif // !UNITY_DOTSRUNTIME

Coverage by test methods


Methods/Properties

IntegerDiff(System.Int32, System.Int32)
GetOutput(GDX.Developer.Reports.Resource.ResourceReportContext, System.Boolean)
GetBeforeAndAfterOutput()
OptionalPercentageOutput()