< Summary

Class:InputController_Tests.InputAction_Measurable_Should
Assembly:InputControllerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/Tests/InputController_Tests.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:164
Line coverage:100% (18 of 18)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%110100%
Return_0_AsDefaultValue()0%110100%
UpdateValueProperly(...)0%110100%
CallOnValueChangedEvent()0%110100%
ReturnDCLActionProperly()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/InputController/Tests/InputController_Tests.cs

#LineLine coverage
 1using System.Collections;
 2using NUnit.Framework;
 3using UnityEngine;
 4using UnityEngine.TestTools;
 5
 6namespace InputController_Tests
 7{
 8    public class InputAction_Trigger_Should
 9    {
 10        private InputAction_Trigger action;
 11
 12        [SetUp]
 13        public void SetUp() { action = ScriptableObject.CreateInstance<InputAction_Trigger>(); }
 14
 15        [Test]
 16        public void Have_WasTriggeredThisFrame_Off_ByDefault() { Assert.IsFalse(action.WasTriggeredThisFrame()); }
 17
 18        [Test]
 19        public void Have_WasTriggeredThisFrame_On_AfterRaisingInTheSameFrame()
 20        {
 21            action.RaiseOnTriggered();
 22            Assert.True(action.WasTriggeredThisFrame());
 23        }
 24
 25        [UnityTest]
 26        public IEnumerator Have_WasTriggeredThisFrame_Off_AfterRaisingInDifferentFrame()
 27        {
 28            action.RaiseOnTriggered();
 29            yield return null;
 30            Assert.False(action.WasTriggeredThisFrame());
 31        }
 32
 33        [Test]
 34        public void CallTriggeredEvent()
 35        {
 36            bool called = false;
 37            action.OnTriggered += x => called = true;
 38
 39            action.RaiseOnTriggered();
 40
 41            Assert.IsTrue(called);
 42        }
 43
 44        [Test]
 45        public void ReturnDCLActionProperly()
 46        {
 47            action.dclAction = DCLAction_Trigger.CameraChange;
 48
 49            Assert.AreEqual(DCLAction_Trigger.CameraChange, action.GetDCLAction());
 50        }
 51
 52        [Test]
 53        public void ReturnIsTriggerBlockedProperly()
 54        {
 55            action.blockTrigger = new BooleanVariable();
 56            action.blockTrigger.Set(true);
 57
 58            Assert.AreEqual(true, action.isTriggerBlocked.Get());
 59        }
 60    }
 61
 62    public class InputAction_Hold_Should
 63    {
 64        private InputAction_Hold action;
 65
 66        [SetUp]
 67        public void SetUp() { action = ScriptableObject.CreateInstance<InputAction_Hold>(); }
 68
 69        [Test]
 70        public void BeOffByDefault() { Assert.IsFalse(action.isOn); }
 71
 72        [Test]
 73        public void CallStartedEvent()
 74        {
 75            bool called = false;
 76            action.OnStarted += x => called = true;
 77
 78            action.RaiseOnStarted();
 79
 80            Assert.IsTrue(called);
 81        }
 82
 83        [Test]
 84        public void CallFinishedEvent()
 85        {
 86            bool called = false;
 87            action.OnFinished += x => called = true;
 88
 89            action.RaiseOnFinished();
 90
 91            Assert.IsTrue(called);
 92        }
 93
 94        [Test]
 95        public void BeOnAfterStartedIsRaised()
 96        {
 97            action.RaiseOnStarted();
 98            Assert.IsTrue(action.isOn);
 99        }
 100
 101        [Test]
 102        public void BeOffAfterFinishedIsRaised()
 103        {
 104            action.RaiseOnStarted();
 105            action.RaiseOnFinished();
 106            Assert.IsFalse(action.isOn);
 107        }
 108
 109        [Test]
 110        public void ReturnDCLActionProperly()
 111        {
 112            action.dclAction = DCLAction_Hold.Sprint;
 113
 114            Assert.AreEqual(DCLAction_Hold.Sprint, action.GetDCLAction());
 115        }
 116    }
 117
 118    public class InputAction_Measurable_Should
 119    {
 120        private InputAction_Measurable action;
 121
 122        [SetUp]
 14123        public void SetUp() { action = ScriptableObject.CreateInstance<InputAction_Measurable>(); }
 124
 125        [Test]
 2126        public void Return_0_AsDefaultValue() { Assert.AreEqual(0, action.GetValue()); }
 127
 128        [Test]
 129        [TestCase(1)]
 130        [TestCase(2)]
 131        [TestCase(-1)]
 132        [TestCase(0.5f)]
 133        public void UpdateValueProperly(float newValue)
 134        {
 4135            action.RaiseOnValueChanged(newValue);
 4136            Assert.AreEqual(newValue, action.GetValue());
 4137        }
 138
 139        [Test]
 140        public void CallOnValueChangedEvent()
 141        {
 1142            var called = false;
 1143            var calledValue = 18f;
 144
 1145            action.OnValueChanged += (x, value) =>
 146            {
 1147                called = true;
 1148                calledValue = value;
 1149            };
 1150            action.RaiseOnValueChanged(18f);
 151
 1152            Assert.IsTrue(called);
 1153            Assert.AreEqual(18f, calledValue);
 1154        }
 155
 156        [Test]
 157        public void ReturnDCLActionProperly()
 158        {
 1159            action.dclAction = DCLAction_Measurable.CameraXAxis;
 160
 1161            Assert.AreEqual(DCLAction_Measurable.CameraXAxis, action.GetDCLAction());
 1162        }
 163    }
 164}