< 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:17
Uncovered lines:2
Coverable lines:19
Total lines:50
Line coverage:89.4% (17 of 19)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InputSpikeFixer(...)0%110100%
GetValue(...)0%330100%
IsInputValueTolerable(...)0%2100%
ShouldIgnoreInputValue(...)0%6200%
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
 79914        public InputSpikeFixer(Func<CursorLockMode> getLockMode)
 15        {
 79916            this.getLockMode = getLockMode;
 79917            lastLockState = getLockMode();
 79918            isLockStateDirty = false;
 79919        }
 20        public float GetValue(float currentValue)
 21        {
 1102322            CheckLockState();
 23
 1102324            float absoluteValue = Mathf.Abs(currentValue);
 25
 1102326            if (ShouldIgnoreInputValue(absoluteValue))
 27            {
 228                if (IsInputValueTolerable(absoluteValue))
 129                    isLockStateDirty = false;
 230                return 0;
 31            }
 32
 1102133            return currentValue;
 34        }
 035        private static bool IsInputValueTolerable(float value) { return value < INPUT_SPIKE_TOLERANCE; }
 036        private bool ShouldIgnoreInputValue(float value) { return value > 0 && isLockStateDirty; }
 37
 38        private void CheckLockState()
 39        {
 1102340            var currentLockState = getLockMode();
 41
 1102342            if (currentLockState != lastLockState)
 43            {
 244                isLockStateDirty = true;
 45            }
 46
 1102347            lastLockState = currentLockState;
 1102348        }
 49    }
 50}