< Summary

Class:ManaCounterView
Assembly:ProfileHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ProfileHUD/ManaCounterView.cs
Covered lines:13
Uncovered lines:7
Coverable lines:20
Total lines:60
Line coverage:65% (13 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetBalance(...)0%220100%
SetBalance(...)0%110100%
FormatBalanceToString(...)0%14.518053.33%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ProfileHUD/ManaCounterView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5/// <summary>
 6/// ProfileHUD sub-view that shows the user MANA balance.
 7/// </summary>
 8internal class ManaCounterView : MonoBehaviour
 9{
 10    [SerializeField] internal TextMeshProUGUI balanceText;
 11    [SerializeField] internal Button_OnPointerDown buttonManaInfo;
 12    [SerializeField] internal Button buttonManaPurchase;
 13
 14    /// <summary>
 15    /// Set the amount of MANA in the HUD.
 16    /// </summary>
 17    /// <param name="balance">Amount of MANA.</param>
 18    public void SetBalance(string balance)
 19    {
 120        double manaBalance = 0;
 121        if (double.TryParse(balance, out manaBalance))
 122            SetBalance(manaBalance);
 123    }
 24
 225    public void SetBalance(double balance) { balanceText.text = FormatBalanceToString(balance); }
 26
 27    private string FormatBalanceToString(double balance)
 28    {
 129        if (balance >= 100000000)
 30        {
 031            return (balance / 1000000D).ToString("0.#M");
 32        }
 133        if (balance >= 1000000)
 34        {
 035            return (balance / 1000000D).ToString("0.##M");
 36        }
 137        if (balance >= 100000)
 38        {
 039            return (balance / 1000D).ToString("0.#K");
 40        }
 141        if (balance >= 10000)
 42        {
 043            return (balance / 1000D).ToString("0.##K");
 44        }
 145        if (balance < 0.001)
 46        {
 047            return "0";
 48        }
 149        if (balance <= 1)
 50        {
 051            return balance.ToString("0.###");
 52        }
 153        if (balance < 100)
 54        {
 155            return balance.ToString("0.##");
 56        }
 57
 058        return balance.ToString("#,0");
 59    }
 60}