Exemplo n.º 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");
        }
Exemplo n.º 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));
        }
Exemplo n.º 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.
        }
Exemplo n.º 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, ?);
        }
Exemplo n.º 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
        }
Exemplo n.º 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");
        }
Exemplo n.º 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
        }
Exemplo n.º 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));
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
        }
        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");
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
        }