< Summary

Class:GDX.Developer.Reports.Resource.ResourceReport
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/ResourceReport.cs
Covered lines:49
Uncovered lines:11
Coverable lines:60
Total lines:152
Line coverage:81.6% (49 of 60)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:9
Method coverage:88.8% (8 of 9)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ResourceReport()0%110100%
Output(...)0%330100%
Output(...)0%4.014091.67%
CreateDivider(...)0%110100%
CreateHeader(...)0%110100%
CreateKeyValuePair(...)0%3.883053.85%
CreateYesNo(...)0%12300%
PositiveSign(...)0%330100%
PositiveSign(...)0%330100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/Reports/Resource/ResourceReport.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
 5#if !UNITY_DOTSRUNTIME
 6
 7using System;
 8using System.IO;
 9using System.Runtime.CompilerServices;
 10using System.Text;
 11
 12namespace GDX.Developer.Reports.Resource
 13{
 14    /// <exception cref="UnsupportedRuntimeException">Not supported on DOTS Runtime.</exception>
 15    public abstract class ResourceReport
 16    {
 17        /// <summary>
 18        ///     A <see cref="string" /> array used to represent the end of a line for splitting purposes.
 19        /// </summary>
 120        static readonly string[] k_NewLineSplit = { Environment.NewLine };
 21
 22        /// <summary>
 23        ///     Output the report format as an array of <see cref="string" />.
 24        /// </summary>
 25        /// <remarks>It is usually best to provide a <see cref="StringBuilder" /> or <see cref="StreamWriter" /> instead
 26        /// <param name="context"></param>
 27        /// <returns>A generated report as an array of <see cref="string" />.</returns>
 28        public string[] Output(ResourceReportContext context = null)
 329        {
 330            StringBuilder builder = new StringBuilder();
 331            return Output(builder, context)
 32                ? builder.ToString().Split(k_NewLineSplit, StringSplitOptions.None)
 33                : null;
 334        }
 35
 36        /// <summary>
 37        ///     Output the report format utilizing the provided <paramref name="writer" />, optionally limiting the
 38        ///     write buffers by <paramref name="bufferSize" />.
 39        /// </summary>
 40        /// <param name="context">Contextual information regarding the generation of the report.</param>
 41        /// <param name="writer">A <see cref="StreamWriter" /> instance to use for output.</param>
 42        /// <param name="bufferSize">The write buffer size.</param>
 43        /// <returns>true/false if the report was successfully written to the provided <paramref name="writer" />.</retu
 44        public bool Output(StreamWriter writer, int bufferSize = 1024, ResourceReportContext context = null)
 145        {
 146            StringBuilder builder = new StringBuilder();
 147            if (!Output(builder, context))
 048            {
 049                return false;
 50            }
 51
 152            int contentLength = builder.Length;
 153            char[] content = new char[bufferSize];
 154            int leftOvers = contentLength % bufferSize;
 155            int writeCount = (contentLength - leftOvers) / bufferSize;
 56
 57            // Fixed sized writes
 21058            for (int i = 0; i < writeCount; i++)
 10459            {
 10460                builder.CopyTo(i * bufferSize, content, 0, bufferSize);
 10461                writer.Write(content, 0, bufferSize);
 10462            }
 63
 164            if (leftOvers > 0)
 165            {
 166                builder.CopyTo(writeCount * bufferSize, content, 0, leftOvers);
 167                writer.Write(content, 0, leftOvers);
 168            }
 69
 170            writer.Flush();
 171            return true;
 172        }
 73
 74        /// <summary>
 75        ///     Output the report format utilizing the provided <paramref name="builder" />.
 76        /// </summary>
 77        /// <param name="builder">A <see cref="StringBuilder" /> to use when generating the report.</param>
 78        /// <param name="context">Contextual information regarding the generation of the report.</param>
 79        /// <returns>true/false if report was added to <paramref name="builder" />.</returns>
 80        public abstract bool Output(StringBuilder builder, ResourceReportContext context = null);
 81
 82
 83        /// <summary>
 84        ///     Create a sized divider string for use in generating reports.
 85        /// </summary>
 86        /// <param name="context">Contextual information regarding the generation of the report.</param>
 87        /// <param name="divider">The optional character to use as the divider.</param>
 88        /// <returns>A sized string to be used as a divider.</returns>
 89        public static string CreateDivider(ResourceReportContext context, char divider = '-')
 190        {
 191            return "".PadRight(context.CharacterWidth, divider);
 192        }
 93
 94        /// <summary>
 95        ///     Create a header with <paramref name="title" /> with repeated <paramref name="decorator" />s on the sides
 96        ///     out to <see cref="ResourceReportContext.CharacterWidth" />.
 97        /// </summary>
 98        /// <param name="context">Contextual information regarding the generation of the report.</param>
 99        /// <param name="title">The text to be treated as the title for the header.</param>
 100        /// <param name="decorator">The optional character to be used as the decorator.</param>
 101        /// <returns>A sized string to be used as a header.</returns>
 102        public static string CreateHeader(ResourceReportContext context, string title, char decorator = '=')
 59103        {
 59104            string workingTitle = $" {title.Trim()} ";
 105
 59106            int titleWidth = workingTitle.Length;
 59107            int decoratorSideWidth = (context.CharacterWidth - titleWidth) / 2;
 108
 109            // Pad left side first to ensure it is always the most accurate in length
 59110            workingTitle = workingTitle.PadLeft(titleWidth + decoratorSideWidth, decorator);
 59111            workingTitle = workingTitle.PadRight(context.CharacterWidth, decorator);
 112
 59113            return workingTitle;
 59114        }
 115
 116        public static string CreateKeyValuePair(ResourceReportContext context, string itemKey, string itemValue)
 131117        {
 131118            string workingLine = $"{itemKey}: ".PadRight(context.KeyValuePairWidth);
 131119            if (workingLine.Length > context.KeyValuePairWidth)
 0120            {
 0121                workingLine = workingLine.Substring(0, context.KeyValuePairWidth);
 0122            }
 123
 131124            workingLine = $"{workingLine}{itemValue}";
 131125            if (workingLine.Length > context.CharacterWidth)
 0126            {
 0127                workingLine = workingLine.Substring(0, context.CharacterWidth);
 0128            }
 129
 131130            return workingLine;
 131131        }
 132
 133        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 134        public static string CreateYesNo(bool flag)
 0135        {
 0136            return flag ? "Y" : "N";
 0137        }
 138
 139        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 140        public static string PositiveSign(long targetValue)
 12141        {
 12142            return targetValue > 0 ? "+" : null;
 12143        }
 144
 145        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 146        public static string PositiveSign(int targetValue)
 1147        {
 1148            return targetValue > 0 ? "+" : null;
 1149        }
 150    }
 151}
 152#endif // !UNITY_DOTSRUNTIME

Coverage by test methods







Methods/Properties

ResourceReport()
Output(GDX.Developer.Reports.Resource.ResourceReportContext)
Output(System.IO.StreamWriter, System.Int32, GDX.Developer.Reports.Resource.ResourceReportContext)
CreateDivider(GDX.Developer.Reports.Resource.ResourceReportContext, System.Char)
CreateHeader(GDX.Developer.Reports.Resource.ResourceReportContext, System.String, System.Char)
CreateKeyValuePair(GDX.Developer.Reports.Resource.ResourceReportContext, System.String, System.String)
CreateYesNo(System.Boolean)
PositiveSign(System.Int64)
PositiveSign(System.Int32)