< Summary

Class:FPSDisplayTests.HiccupTests
Assembly:FPSDisplayTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/Tests/HiccupTests.cs
Covered lines:41
Uncovered lines:0
Coverable lines:41
Total lines:101
Line coverage:100% (41 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BehavesLikeFPSCounter()0%220100%
DetectsOneHiccup()0%220100%
CorrectlyAccountsTimeInHiccups()0%330100%
GetSumOfHiccupsAndTime()0%440100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/Tests/HiccupTests.cs

#LineLine coverage
 1using DCL.FPSDisplay;
 2using NUnit.Framework;
 3using UnityEngine;
 4using System.Collections;
 5
 6namespace FPSDisplayTests
 7{
 8    public class HiccupTests
 9    {
 10        [Test]
 11        public void BehavesLikeFPSCounter()
 12        {
 113            LinealBufferHiccupCounter counter = new LinealBufferHiccupCounter();
 14
 15            const float tenMillis = 0.01f;
 16            const float expectedFps = 100.0f;
 17
 20218            for (int i = 0; i < 100; i++)
 19            {
 10020                counter.AddDeltaTime(tenMillis);
 21            }
 22
 123            Assert.AreEqual(counter.CurrentFPSCount(), expectedFps);
 124        }
 25
 26        [Test]
 27        public void DetectsOneHiccup()
 28        {
 129            LinealBufferHiccupCounter counter = new LinealBufferHiccupCounter();
 30
 31            const float tenMillis = 0.01f;
 32
 20233            for (int i = 0; i < 100; i++)
 34            {
 10035                counter.AddDeltaTime(tenMillis);
 36            }
 37
 138            counter.AddDeltaTime(FPSEvaluation.HICCUP_THRESHOLD_IN_SECONDS + 0.01f);
 39
 140            Assert.AreEqual(counter.HiccupsCountInBuffer, 1);
 141        }
 42
 43        [Test]
 44        public void CorrectlyAccountsTimeInHiccups()
 45        {
 146            LinealBufferHiccupCounter counter = new LinealBufferHiccupCounter();
 47
 148            float hiccups = 0.0f;
 149            int hiccupCount = 0;
 50
 200251            for (int i = 0; i < 1000; i++)
 52            {
 100053                float value = Random.Range(0.001f, 1f);
 100054                counter.AddDeltaTime(value);
 100055                if (value > FPSEvaluation.HICCUP_THRESHOLD_IN_SECONDS)
 56                {
 95457                    hiccups += value;
 95458                    hiccupCount += 1;
 59                }
 60            }
 61
 162            Assert.AreEqual(counter.HiccupsSum, hiccups);
 163            Assert.AreEqual(counter.HiccupsCountInBuffer, hiccupCount);
 164        }
 65
 66        [Test]
 67        public void GetSumOfHiccupsAndTime()
 68        {
 169            LinealBufferHiccupCounter counter = new LinealBufferHiccupCounter();
 70
 171            float hiccups = 0.0f;
 172            float totalTime = 0.0f;
 173            int hiccupCount = 0;
 74
 75            // Fill in random values
 300276            for (int i = 0; i < 1500; i++)
 77            {
 150078                float value = Random.Range(0.001f, 1f);
 150079                counter.AddDeltaTime(value);
 80            }
 81
 200282            for (int i = 0; i < 1000; i++)
 83            {
 100084                float value = Random.Range(0.001f, 1f);
 100085                totalTime += value;
 100086                if (value > FPSEvaluation.HICCUP_THRESHOLD_IN_SECONDS)
 87                {
 95888                    hiccupCount += 1;
 95889                    hiccups += value;
 90                }
 91
 100092                counter.AddDeltaTime(value);
 93            }
 94
 95            const float eps = 0.002f;
 196            Assert.LessOrEqual(Mathf.Abs(counter.HiccupsSum - hiccups), eps);
 197            Assert.AreEqual(counter.HiccupsCountInBuffer, hiccupCount);
 198            Assert.LessOrEqual(Mathf.Abs(counter.GetTotalSeconds() - totalTime), eps);
 199        }
 100    }
 101}