예제 #1
0
        /// <summary>
        /// Loads the scene, loads the level, and then tries to walk through all the guides.
        /// Useful for catching guides with invalid targets.
        /// <para>Argument <paramref name="data"/> can be fed using the <see cref="ValueSourceAttribute"/> in combination
        /// with using <see cref="PlaygroundTestHelper.GetActiveLevels"/> from <see cref="PlaygroundTestHelper"/>.</para>
        /// <para>Note: Needs attribute <see cref="UnityTestAttribute"/> to be applied on the overridden method
        /// in your derived class for Unity Test Runner to find the method.</para>
        /// </summary>
        /// <param name="data">The level data. Use <see cref="PlaygroundTestHelper.GetActiveLevels"/>
        /// from <see cref="PlaygroundTestHelper"/> to feed automatically.</param>
        public virtual IEnumerator TestPlayGuidesInLevel(LevelTestData data)
        {
            // Arrange
            Main.instance.StartGame(data.levelIndex);
            int expectedCount = data.levelData.guideBubbles?.Count ?? 0;
            int actualCount   = 0;

            yield return(null);

            // Act
            if (!string.IsNullOrEmpty(data.levelData.levelSettings?.taskDescription?.header))
            {
                Assert.IsTrue(UISingleton.instance.taskDescription.bigTaskDescription.activeSelf,
                              "Did not mark {0} as active for {1}", nameof(TaskDescriptionController.bigTaskDescription), data);
                Assert.IsTrue(Progress.instance.levelData[data.levelData.id].hasShownDescription,
                              "Did not mark {0} as true for {1}", nameof(LevelData.hasShownDescription), data);
                UISingleton.instance.taskDescription.bigTaskDescription.SetActive(false);
            }
            else
            {
                Assert.IsFalse(UISingleton.instance.taskDescription.bigTaskDescription.activeSelf,
                               "Game object {0} was active while it should not have been for {1}",
                               nameof(TaskDescriptionController.bigTaskDescription), data);
                Assert.IsFalse(Progress.instance.levelData[data.levelData.id].hasShownDescription,
                               "Field {0} was true while it should not have been for {1}", nameof(LevelData.hasShownDescription),
                               data);
            }

            yield return(new WaitForSeconds(0.1f));

            while (UISingleton.instance.guidePlayer.currentGuide?.hasNext == true ||
                   UISingleton.instance.guideBubble.isShowing)
            {
                yield return(new WaitForSeconds(0.1f));

                if (UISingleton.instance.guideBubble.isShowing)
                {
                    UISingleton.instance.guideBubble.HideMessage();
                    actualCount++;
                }

                yield return(null);
            }

            // Assert
            Assert.AreEqual(expectedCount, actualCount, "Number of guides shown did not match.");

            // Asserting is done by assuming no exceptions & no error logs
        }
예제 #2
0
        [Timeout(60_000)]         // ms to complete ALL cases for level
        public virtual IEnumerator TestPlayLevel(LevelTestData data)
        {
            // Arrange
            const float caseTimeLimit = 10;             // seconds

            Main.instance.ignorePlayingGuides = true;
            Main.instance.StartGame(data.levelIndex);
            yield return(null);

            PMWrapper.speedMultiplier = 1;

            var postSceneLoad = PostSceneLoad();

            while (postSceneLoad != null && postSceneLoad.MoveNext())
            {
                yield return(postSceneLoad.Current);
            }
            yield return(null);


            // Act
            if (!string.IsNullOrWhiteSpace(data.levelData.levelSettings?.exampleSolutionCode))
            {
                PMWrapper.mainCode = data.levelData.levelSettings.exampleSolutionCode;
            }
            else
            {
                Assert.Inconclusive($"Level '{data.levelData.id}' ({data.scene.name}) has no example solution.");
            }

            float start = Time.time;

            do
            {
                IEnumerator coroutine = PlaygroundTestHelper.RunCaseAndAssert(data);
                while (coroutine.MoveNext())
                {
                    yield return(coroutine.Current);
                }

                Assert.IsTrue(Time.time - start < caseTimeLimit,
                              $"Compiler execution timeout! Compiler took too long to complete ALL cases in {data}. Waited {caseTimeLimit} seconds.");
            } while (!Main.instance.caseHandler.allCasesCompleted);

            // Asserting is done by assuming no exceptions & no error logs
        }
예제 #3
0
 public override IEnumerator TestPlayLevel([ValueSource(nameof(GetActiveLevels))] LevelTestData data)
 {
     return(base.TestPlayLevel(data));
 }