< Summary

Class:GDX.Developer.SimpleWatch
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/Watches/SimpleWatch.cs
Covered lines:10
Uncovered lines:9
Coverable lines:19
Total lines:55
Line coverage:52.6% (10 of 19)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:2
Method coverage:50% (1 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SimpleWatch(...)0%110100%
Poll()0%6200%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/Watches/SimpleWatch.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_2022_2_OR_NEWER
 6
 7using System;
 8using UnityEngine.UIElements;
 9
 10namespace GDX.Developer
 11{
 12
 13    /// <summary>
 14    /// Thread-safe developer watch system.
 15    /// </summary>
 16    public class SimpleWatch : WatchBase
 17    {
 18        readonly Func<string> m_GetValue;
 19        int m_CachedHash;
 20
 21        readonly Label m_DisplayNameLabel;
 22        readonly Label m_ValueLabel;
 23
 24        public SimpleWatch(string uniqueIdentifier, string displayName, Func<string> getValue, bool enabled = true, int 
 225            : base(uniqueIdentifier, displayName, enabled, minWidth, minHeight)
 226        {
 227            m_GetValue = getValue;
 28
 229            m_DisplayNameLabel = new Label() { text = displayName };
 230            m_DisplayNameLabel.AddToClassList("gdx-watch-left");
 31
 232            m_ValueLabel = new Label();
 233            m_ValueLabel.AddToClassList("gdx-watch-right");
 34
 235            ContainerElement.Add(m_DisplayNameLabel);
 236            ContainerElement.Add(m_ValueLabel);
 237        }
 38
 39        public override void Poll()
 040        {
 41            // Poll for our new value
 042            string getValue = m_GetValue();
 043            int getValueHash = getValue.GetStableHashCode();
 44
 45            // Only change if legit change
 046            if (m_CachedHash != getValueHash)
 047            {
 048                m_ValueLabel.text = getValue;
 049                m_CachedHash = getValueHash;
 050            }
 051        }
 52    }
 53}
 54
 55#endif // UNITY_2022_2_OR_NEWER

Coverage by test methods


Methods/Properties

SimpleWatch(System.String, System.String, System.Func[String], System.Boolean, System.Int32, System.Int32)
Poll()