コード例 #1
0
        public IEnumerator TrailGetsLongerDuringRace()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");
            var originalTronBackBorder = GeometryUtils.GetBackBorder(tron);

            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            var tronMoved = new ObjectMovedPredicate(tronTransform, 0.5f);
            var waiter    = new WaitUntilOrTimeout(tronMoved.HasMoved, 2.0f);

            yield return(waiter);

            waiter.AssertTimeoutWasNotReached("move of Tron");

            var currentTronBackBorder = GeometryUtils.GetBackBorder(tron);
            var trail = Find.SingleObjectById("Trail");
            // still at same back position
            var trailBackBorder = GeometryUtils.GetBackBorder(trail);

            var comparer = new Vector3EqualityComparer(0.0001f);

            Assert.That(trailBackBorder, Is.EqualTo(originalTronBackBorder).Using(comparer), "trailBackBorder");
            var trailFrontBorder = GeometryUtils.GetFrontBorder(trail);

            Assert.That(trailFrontBorder, Is.EqualTo(currentTronBackBorder).Using(comparer), "trailFrontBorder");
        }
コード例 #2
0
        public IEnumerator StartsRacingOnButtonClick()
        {
            Time.timeScale = 10.0f;

            yield return(Given.Scene(this, "MainScene"));

            var tron             = Find.SingleObjectById("Tron");
            var tronTransform    = tron.transform;
            var originalPosition = tronTransform.position;

            // was tronTransform.GetComponent<Tron>().StartRace();
            ClickStartButton();

            const float someDistance = 0.5f;
            var         tronMoved    = new ObjectMovedPredicate(tronTransform, someDistance);
            var         waiter       = new WaitUntilOrTimeout(tronMoved.HasMoved, 2.0f);

            yield return(waiter);

            waiter.AssertTimeoutWasNotReached("move of Tron");

            // ReSharper disable once Unity.InefficientPropertyAccess
            var newPosition = tronTransform.position;

            Assert.That(newPosition.y, Is.EqualTo(originalPosition.y));
            Assert.That(tronMoved.CurrentDistance, Is.GreaterThan(someDistance));
        }
コード例 #3
0
        public IEnumerator Exists()
        {
            yield return(Given.Scene(this, "MainScene"));

            const string objectId = "Grid";
            var          grid     = Find.SingleObjectById(objectId);

            AssertThat.IsVisible(grid, objectId);
            // TODO Do we need to test the size of the grid?
            // Definitely not test the colour of the grid.
        }
コード例 #4
0
        public IEnumerator IsInSceneOnStartup()
        {
            yield return(Given.Scene(this, "MainScene"));

            const string objectId = "Tron";
            var          tron     = Find.SingleObjectById(objectId);

            AssertThat.IsVisible(tron, objectId + "visible");
            AssertIsTripleAsHigh(tron, objectId);
            // not assertThatSize(tron, ?);
            // not assertThatPosition(tron, ?);
        }
コード例 #5
0
        public IEnumerator FacesRightAfterTurnRight()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron          = Find.SingleObjectById("Tron");
            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            tronTransform.GetComponent <RacingInteraction>().TurnRight();
            yield return(new WaitForEndOfFrame());

            // assert tronTransformation.rotation, bla
        }
コード例 #6
0
        public IEnumerator CreatesTrailWhenStartRacing()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");

            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            var trail = Find.SingleObjectById("Trail");

            AssertThat.IsVisible(trail, "Trail" + "visible");
        }
コード例 #7
0
        public IEnumerator TrailBottomIsCreatedAtTronBottom()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");

            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            var trail = Find.SingleObjectById("Trail");

            Assert.That(trail.transform.position.y, Is.EqualTo(tronTransform.position.y), "trail.y");
            // Assert trail is internally aligned that its base is the bottom - manual
        }
コード例 #8
0
        public IEnumerator DoesntTurnRightWhenGameHasNotStarted()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron              = Find.SingleObjectById("Tron");
            var tronTransform     = tron.transform;
            var racingInteraction = tron.AddComponent <RacingInteractionSpy>();

            tronTransform.GetComponent <Tron>().racingInteraction = racingInteraction;
            // NO tronTransform.GetComponent<Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            yield return(_inputSimulation.PressRight());

            Assert.That(racingInteraction.TurnRightCallCount(), Is.EqualTo(0));
        }
コード例 #9
0
        public IEnumerator TrailBackBorderIsCreatedAtTronBackBorder()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");
            var originalTronBackBorder = GeometryUtils.GetBackBorder(tron);

            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            var trail           = Find.SingleObjectById("Trail");
            var trailBackBorder = GeometryUtils.GetBackBorder(trail);

            Assert.That(trailBackBorder, Is.EqualTo(originalTronBackBorder), "trailBackBorder");
        }
コード例 #10
0
        public IEnumerator TrailHeightIsTronHeightAndHalfWidth()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");

            var tronTransform = tron.transform;

            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            var trail      = Find.SingleObjectById("Trail");
            var trailScale = trail.transform.localScale;
            var tronScale  = tronTransform.localScale;

            Assert.That(trailScale.y, Is.EqualTo(tronScale.y), "trail height");
            Assert.That(trailScale.x, Is.EqualTo(tronScale.x / 2), "trail width");
        }
コード例 #11
0
        public IEnumerator StartsGameOnButtonClick()
        {
            yield return(Given.Scene(this, "MainScene"));

            yield return(new WaitForEndOfFrame());

            var tron    = Find.SingleObjectById("Tron");
            var tronSpy = tron.AddComponent <TronSpy>();

            var buttonGameObject = Find.SingleObjectById("StartButton");
            var button           = buttonGameObject.GetComponent <Button>();

            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(tronSpy.StartRace);

            // Trying to  get the simulation of the button click to work. No success.
            // It feels like Fixture is not connected to UI somehow. Experiments below...
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForSeconds(10));

            // first try: button.onClick.Invoke(); - works of course
            button.Select();

            var buttonRectTransform = button.GetComponent <RectTransform>();

            // var buttonRect = buttonRectTransform.rect;
            // var buttonCenter = buttonRect.position;
            // yield return _inputSimulation.MouseLeftClick(buttonRectTransform.position);

            yield return(new WaitForSeconds(15));

            yield return(new WaitForEndOfFrame());

            yield return(new WaitForEndOfFrame());

            Assert.That(tronSpy.StartRacingHasBeenCalled(), Is.True,
                        "tronSpy.StartRacingHasBeenCalled() has been called");
        }
コード例 #12
0
        public IEnumerator IsOnGridOnStartup()
        {
            yield return(Given.Scene(this, "MainScene"));

            const string objectId = "Tron";
            var          tron     = Find.SingleObjectById(objectId);

            // Tron is based on plane
            Assert.That(tron.transform.position.y, Is.EqualTo(0), objectId + ".y");

            // ReSharper disable CommentTypo
            // Tron internally is aligned that its base is the bottom
            // Do we write a test for that or edit in the editor? Seems like Gui fiddeling?
            // Assert trail is internally aligned that its base is the bottom - manual
            // ReSharper restore CommentTypo

            // Grid plane is also at 0
            var grid = Find.SingleObjectById("Grid");

            Assert.That(grid.transform.position.y, Is.EqualTo(0), "grid.y");
        }
コード例 #13
0
        public IEnumerator ShouldTriggerTurnRightOnlyOnKeyPressStarted()
        {
            yield return(Given.Scene(this, "MainScene"));

            var tron = Find.SingleObjectById("Tron");

            // TODO duplication: extract mock creation to helper method
            var tronTransform     = tron.transform; // TODO: do we need transform? direct?
            var racingInteraction = tron.AddComponent <RacingInteractionSpy>();

            tronTransform.GetComponent <Tron>().racingInteraction = racingInteraction;

            // TODO duplication: We have lots of calls like this. Maybe have Given.RaceStarted()
            // need also var tronTransform = tron.transform;
            tronTransform.GetComponent <Tron>().StartRace();
            yield return(new WaitForEndOfFrame());

            yield return(_inputSimulation.PressRight());

            // TODO duplication: extract mock verification to helper methods
            Assert.That(racingInteraction.TurnRightCallCount(), Is.EqualTo(1), "TurnRight has been called");
        }