< Summary

Class:DroneGame.Drone
Assembly:Drone
File(s):/github/workspace/Assets/Scripts/Drone.cs
Covered lines:18
Uncovered lines:5
Coverable lines:23
Total lines:64
Line coverage:78.2% (18 of 23)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:2
Method coverage:50% (1 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%6200%
FollowPath()0%66095.24%

File(s)

/github/workspace/Assets/Scripts/Drone.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DroneGame
 7{
 8  public class Drone : MonoBehaviour
 9  {
 10    Grid _grid;
 11    Button _button;
 12
 13    public bool alreadyMoving;
 14
 15    /// <summary>Set the move speed of the drone</summary>
 16    [SerializeField]
 17    [Range(0.1f, 10.0f)]
 18    float _moveSpeed;
 19
 20    /// <summary>This is here to mostly just setup the height, but it's a vector3 to facilitate to use in math</summary>
 21    [SerializeField] Vector3 _coordinateAdjustment;
 22
 23    /// <summary>Default Unity event, Start executes when th object is instantiated and happens after Awake is executed<
 24    public void Initialize(Grid grid)
 025    {
 026      _grid = grid;
 027      _button = GameObject.Find("CalculateAndMoveButton").GetComponent<Button>() ?? throw new("Button not found");
 028      transform.position = _grid.GetTileWorldCoordinate("A1") + _coordinateAdjustment;
 029    }
 30
 31    /// <summary>This function is meant to be executed as a coroutine
 32    /// Make drone move along the specified path.</summary>
 33    public IEnumerator FollowPath(List<TileData> path)
 134    {
 135      if (alreadyMoving) throw new("Drone is already moving");
 36
 137      alreadyMoving = true;
 38#if !UNITY_INCLUDE_TESTS
 39      _button.interactable = false;
 40#endif
 441      for (int tileIndex = 1; tileIndex < path.Count; tileIndex++)
 142      {
 143        var currLerp = 0f;
 144        var previousTile = path[tileIndex - 1].globalCoordinates + _coordinateAdjustment;
 145        var nextTile = path[tileIndex].globalCoordinates + _coordinateAdjustment;
 46
 347        while (currLerp <= 1f)
 248        {
 249          var currSpeed = _moveSpeed * Time.deltaTime;
 250          transform.position = Vector3.Lerp(previousTile, nextTile, currLerp);
 51
 52          // And this is the reason why this works
 53          // Wait for the next frame to continue the code execution.
 254          yield return null;
 255          currLerp += currSpeed;
 256        }
 157      }
 158      alreadyMoving = false;
 59#if !UNITY_INCLUDE_TESTS
 60      _button.interactable = true;
 61#endif
 162    }
 63  }
 64}