< Summary

Class:DCL.Camera.InputSpikeFixer
Assembly:Camera
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/InputSpikeFixer.cs
Covered lines:19
Uncovered lines:0
Coverable lines:19
Total lines:50
Line coverage:100% (19 of 19)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:5
Method coverage:100% (5 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputSpikeFixer(...)0%110100%
GetValue(...)0%330100%
IsInputValueTolerable(...)0%110100%
ShouldIgnoreInputValue(...)0%220100%
CheckLockState()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Camera/InputSpikeFixer.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Camera
 5{
 6    public class InputSpikeFixer
 7    {
 8        private const float INPUT_SPIKE_TOLERANCE = 10f;
 9        private readonly Func<CursorLockMode> getLockMode;
 10
 11        private CursorLockMode lastLockState;
 12        private bool isLockStateDirty;
 13
 97014        public InputSpikeFixer(Func<CursorLockMode> getLockMode)
 15        {
 97016            this.getLockMode = getLockMode;
 97017            lastLockState = getLockMode();
 97018            isLockStateDirty = false;
 97019        }
 20        public float GetValue(float currentValue)
 21        {
 1182822            CheckLockState();
 23
 1182824            float absoluteValue = Mathf.Abs(currentValue);
 25
 1182826            if (ShouldIgnoreInputValue(absoluteValue))
 27            {
 228                if (IsInputValueTolerable(absoluteValue))
 129                    isLockStateDirty = false;
 230                return 0;
 31            }
 32
 1182633            return currentValue;
 34        }
 235        private static bool IsInputValueTolerable(float value) { return value < INPUT_SPIKE_TOLERANCE; }
 1182836        private bool ShouldIgnoreInputValue(float value) { return value > 0 && isLockStateDirty; }
 37
 38        private void CheckLockState()
 39        {
 1182840            var currentLockState = getLockMode();
 41
 1182842            if (currentLockState != lastLockState)
 43            {
 244                isLockStateDirty = true;
 45            }
 46
 1182847            lastLockState = currentLockState;
 1182848        }
 49    }
 50}