| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL; |
| | 5 | | using DCL.FPSDisplay; |
| | 6 | | using DCL.SettingsData; |
| | 7 | | using NSubstitute; |
| | 8 | | using NUnit.Framework; |
| | 9 | | using UnityEngine; |
| | 10 | | using QualitySettings = DCL.SettingsData.QualitySettings; |
| | 11 | |
|
| | 12 | | namespace Tests |
| | 13 | | { |
| | 14 | | public class AutoQualitySettingsComponentShould : IntegrationTestSuite_Legacy |
| | 15 | | { |
| | 16 | | private AutoQualitySettingsComponent component; |
| | 17 | |
|
| | 18 | | protected override IEnumerator SetUp() |
| | 19 | | { |
| | 20 | | yield return base.SetUp(); |
| | 21 | | component = CreateTestGameObject("controllerHolder").AddComponent<AutoQualitySettingsComponent>(); |
| | 22 | | Settings.i.autoqualitySettings = ScriptableObject.CreateInstance<QualitySettingsData>(); |
| | 23 | | component.qualitySettings.Set(new [] |
| | 24 | | { |
| | 25 | | Settings.i.qualitySettings, |
| | 26 | | Settings.i.qualitySettings, |
| | 27 | | Settings.i.qualitySettings, |
| | 28 | | Settings.i.qualitySettings, |
| | 29 | | }); |
| | 30 | | } |
| | 31 | |
|
| | 32 | | [Test] |
| | 33 | | public void CreateCappedControllerProperly() |
| | 34 | | { |
| | 35 | | component.fpsCapped = false; |
| | 36 | | component.OnQualitySettingsChanged(new QualitySettings { fpsCap = true }); |
| | 37 | |
|
| | 38 | | Assert.IsTrue(component.fpsCapped); |
| | 39 | | Assert.IsInstanceOf<AutoQualityCappedFPSController>(component.controller); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void CreateUncappedControllerProperly() |
| | 44 | | { |
| | 45 | | component.fpsCapped = true; |
| | 46 | | component.OnQualitySettingsChanged(new QualitySettings { fpsCap = false }); |
| | 47 | |
|
| | 48 | | Assert.IsFalse(component.fpsCapped); |
| | 49 | | Assert.IsInstanceOf<AutoQualityUncappedFPSController>(component.controller); |
| | 50 | | } |
| | 51 | | } |
| | 52 | |
|
| | 53 | | public class AutoQualityCappedFPSControllerShould : IntegrationTestSuite_Legacy |
| | 54 | | { |
| | 55 | | private AutoQualityCappedFPSController controller; |
| | 56 | | private QualitySettingsData qualities; |
| | 57 | |
|
| | 58 | | protected override IEnumerator SetUp() |
| | 59 | | { |
| 4 | 60 | | yield return base.SetUp(); |
| 4 | 61 | | qualities = ScriptableObject.CreateInstance<QualitySettingsData>(); |
| 4 | 62 | | qualities.Set(new [] |
| | 63 | | { |
| | 64 | | Settings.i.qualitySettings, |
| | 65 | | Settings.i.qualitySettings, |
| | 66 | | Settings.i.qualitySettings, |
| | 67 | | Settings.i.qualitySettings, |
| | 68 | | Settings.i.qualitySettings, |
| | 69 | | Settings.i.qualitySettings, |
| | 70 | | Settings.i.qualitySettings, |
| | 71 | | Settings.i.qualitySettings, |
| | 72 | | Settings.i.qualitySettings, |
| | 73 | | }); |
| 4 | 74 | | controller = new AutoQualityCappedFPSController(30, 0, qualities); |
| 4 | 75 | | } |
| | 76 | |
|
| | 77 | | [Test] |
| | 78 | | public void StayIfNotEnoughData() |
| | 79 | | { |
| 1 | 80 | | int initialIndex = qualities.Length / 2; |
| 1 | 81 | | controller.currentQualityIndex = initialIndex; |
| | 82 | |
|
| | 83 | | int newQualityIndex; |
| 12 | 84 | | for (int i = 0; i < AutoQualityCappedFPSController.EVALUATIONS_SIZE; i++) |
| | 85 | | { |
| 5 | 86 | | newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = 0 }); |
| 5 | 87 | | Assert.AreEqual(initialIndex, newQualityIndex); |
| | 88 | | } |
| | 89 | |
|
| 1 | 90 | | newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = 0 }); |
| 1 | 91 | | Assert.AreNotEqual(initialIndex, newQualityIndex); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [Test] |
| | 95 | | public void DecreaseIfBadPerformance() |
| | 96 | | { |
| 1 | 97 | | int initialIndex = qualities.Length / 2; |
| 1 | 98 | | controller.currentQualityIndex = initialIndex; |
| | 99 | |
|
| 1 | 100 | | float belowAcceptableFPS = controller.targetFPS * Mathf.Lerp( 0, AutoQualityCappedFPSController.STAY_MARGIN, |
| 1 | 101 | | controller.fpsEvaluations.Clear(); |
| 1 | 102 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(belowAcceptableFPS, AutoQualityCappedFPSController.EVAL |
| | 103 | |
|
| 1 | 104 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = belowAcceptableFPS |
| 1 | 105 | | Assert.AreEqual(initialIndex - 1, newQualityIndex); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | [Test] |
| | 109 | | public void StayIfAcceptablePerformance() |
| | 110 | | { |
| 1 | 111 | | int initialIndex = qualities.Length / 2; |
| 1 | 112 | | controller.currentQualityIndex = initialIndex; |
| | 113 | |
|
| 1 | 114 | | float acceptableFPS = controller.targetFPS * Mathf.Lerp( AutoQualityCappedFPSController.STAY_MARGIN, AutoQua |
| 1 | 115 | | controller.fpsEvaluations.Clear(); |
| 1 | 116 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(acceptableFPS, AutoQualityCappedFPSController.EVALUATIO |
| | 117 | |
|
| 1 | 118 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = acceptableFPS }); |
| 1 | 119 | | Assert.AreEqual(initialIndex, newQualityIndex); |
| 1 | 120 | | } |
| | 121 | |
|
| | 122 | | [Test] |
| | 123 | | public void IncreaseIfGreatPerformance() |
| | 124 | | { |
| 1 | 125 | | int initialIndex = qualities.Length / 2; |
| 1 | 126 | | controller.currentQualityIndex = initialIndex; |
| | 127 | |
|
| 1 | 128 | | float greatFPS = controller.targetFPS * Mathf.Lerp( AutoQualityCappedFPSController.INCREASE_MARGIN, 1, 0.5f) |
| 1 | 129 | | controller.fpsEvaluations.Clear(); |
| 1 | 130 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(greatFPS, AutoQualityCappedFPSController.EVALUATIONS_SI |
| | 131 | |
|
| 1 | 132 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = greatFPS }); |
| 1 | 133 | | Assert.AreEqual(initialIndex + 2, newQualityIndex); |
| 1 | 134 | | } |
| | 135 | | } |
| | 136 | |
|
| | 137 | | public class AutoQualityUncappedFPSControllerShould : IntegrationTestSuite_Legacy |
| | 138 | | { |
| | 139 | | private AutoQualityUncappedFPSController controller; |
| | 140 | | private QualitySettingsData qualities; |
| | 141 | |
|
| | 142 | | protected override IEnumerator SetUp() |
| | 143 | | { |
| | 144 | | yield return base.SetUp(); |
| | 145 | | qualities = ScriptableObject.CreateInstance<QualitySettingsData>(); |
| | 146 | | qualities.Set(new [] |
| | 147 | | { |
| | 148 | | Settings.i.qualitySettings, |
| | 149 | | Settings.i.qualitySettings, |
| | 150 | | Settings.i.qualitySettings, |
| | 151 | | Settings.i.qualitySettings, |
| | 152 | | Settings.i.qualitySettings, |
| | 153 | | Settings.i.qualitySettings, |
| | 154 | | Settings.i.qualitySettings, |
| | 155 | | Settings.i.qualitySettings, |
| | 156 | | Settings.i.qualitySettings, |
| | 157 | | }); |
| | 158 | | controller = new AutoQualityUncappedFPSController(0, qualities); |
| | 159 | | } |
| | 160 | |
|
| | 161 | | [Test] |
| | 162 | | public void StayIfNotEnoughData() |
| | 163 | | { |
| | 164 | | int initialIndex = qualities.Length / 2; |
| | 165 | | controller.currentQualityIndex = initialIndex; |
| | 166 | |
|
| | 167 | | int newQualityIndex; |
| | 168 | | for (int i = 0; i < AutoQualityCappedFPSController.EVALUATIONS_SIZE; i++) |
| | 169 | | { |
| | 170 | | newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = 0 }); |
| | 171 | | Assert.AreEqual(initialIndex, newQualityIndex); |
| | 172 | | } |
| | 173 | |
|
| | 174 | | newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = 0 }); |
| | 175 | | Assert.AreNotEqual(initialIndex, newQualityIndex); |
| | 176 | | } |
| | 177 | |
|
| | 178 | | [Test] |
| | 179 | | public void DecreaseIfBadPerformance() |
| | 180 | | { |
| | 181 | | int initialIndex = qualities.Length / 2; |
| | 182 | | controller.currentQualityIndex = initialIndex; |
| | 183 | |
|
| | 184 | | float belowAcceptableFPS = FPSEvaluation.WORSE; |
| | 185 | | controller.fpsEvaluations.Clear(); |
| | 186 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(belowAcceptableFPS, AutoQualityCappedFPSController.EVAL |
| | 187 | |
|
| | 188 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = belowAcceptableFPS |
| | 189 | | Assert.AreEqual(initialIndex - 1, newQualityIndex); |
| | 190 | | } |
| | 191 | |
|
| | 192 | | [Test] |
| | 193 | | public void StayIfAcceptablePerformance() |
| | 194 | | { |
| | 195 | | int initialIndex = qualities.Length / 2; |
| | 196 | | controller.currentQualityIndex = initialIndex; |
| | 197 | |
|
| | 198 | | float acceptableFPS = FPSEvaluation.GOOD; |
| | 199 | | controller.fpsEvaluations.Clear(); |
| | 200 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(acceptableFPS, AutoQualityCappedFPSController.EVALUATIO |
| | 201 | |
|
| | 202 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = acceptableFPS }); |
| | 203 | | Assert.AreEqual(initialIndex, newQualityIndex); |
| | 204 | | } |
| | 205 | |
|
| | 206 | | [Test] |
| | 207 | | public void IncreaseIfGreatPerformance() |
| | 208 | | { |
| | 209 | | int initialIndex = qualities.Length / 2; |
| | 210 | | controller.currentQualityIndex = initialIndex; |
| | 211 | |
|
| | 212 | | float greatFPS = FPSEvaluation.GREAT; |
| | 213 | | controller.fpsEvaluations.Clear(); |
| | 214 | | controller.fpsEvaluations.AddRange(Enumerable.Repeat(greatFPS, AutoQualityCappedFPSController.EVALUATIONS_SI |
| | 215 | |
|
| | 216 | | int newQualityIndex = controller.EvaluateQuality(new PerformanceMetricsData { fpsCount = greatFPS }); |
| | 217 | | Assert.AreEqual(initialIndex + 1, newQualityIndex); |
| | 218 | | } |
| | 219 | | } |
| | 220 | | } |