< 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

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
 121514        public InputSpikeFixer(Func<CursorLockMode> getLockMode)
 15        {
 121516            this.getLockMode = getLockMode;
 121517            lastLockState = getLockMode();
 121518            isLockStateDirty = false;
 121519        }
 20        public float GetValue(float currentValue)
 21        {
 2959122            CheckLockState();
 23
 2959124            float absoluteValue = Mathf.Abs(currentValue);
 25
 2959126            if (ShouldIgnoreInputValue(absoluteValue))
 27            {
 228                if (IsInputValueTolerable(absoluteValue))
 129                    isLockStateDirty = false;
 230                return 0;
 31            }
 32
 2958933            return currentValue;
 34        }
 235        private static bool IsInputValueTolerable(float value) { return value < INPUT_SPIKE_TOLERANCE; }
 2959136        private bool ShouldIgnoreInputValue(float value) { return value > 0 && isLockStateDirty; }
 37
 38        private void CheckLockState()
 39        {
 2959140            var currentLockState = getLockMode();
 41
 2959142            if (currentLockState != lastLockState)
 43            {
 244                isLockStateDirty = true;
 45            }
 46
 2959147            lastLockState = currentLockState;
 2959148        }
 49    }
 50}