< Summary

Class:LaunchAngleCsvInterpolator
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Algorithms/Planning/LaunchAngleCsvInterpolator.cs
Covered lines:6
Uncovered lines:13
Coverable lines:19
Total lines:49
Line coverage:31.5% (6 of 19)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:3
Method coverage:66.6% (2 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LaunchAngleCsvInterpolator(...)0%110100%
LaunchAngleCsvInterpolator(...)0%110100%
InitInterpolator()0%20400%

File(s)

/github/workspace/Assets/Scripts/Algorithms/Planning/LaunchAngleCsvInterpolator.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Linq;
 4using UnityEngine;
 5
 6// The launch angle CSV interpolator loads launch angle data from a CSV file and provides
 7// interpolated values for arbitrary target positions.
 8public class LaunchAngleCsvInterpolator : LaunchAngleInterpolatorBase {
 9  // Path to the CSV file.
 10  // The first two columns of the CSV file specify the coordinates of each data point.
 11  // The third column denotes the launch angle in degrees, and the fourth column denotes the time to
 12  // reach the target position.
 13  private readonly string _relativePath;
 14
 15  // Delegate for loading the CSV file.
 16  public delegate string ConfigLoaderDelegate(string path);
 17  private readonly ConfigLoaderDelegate _configLoader;
 18
 19  public LaunchAngleCsvInterpolator(IAgent agent)
 1420      : this(agent, path: Path.Combine("Planning", "hydra70_launch_angle.csv"),
 2821             configLoader: ConfigLoader.LoadFromStreamingAssets) {}
 22  public LaunchAngleCsvInterpolator(IAgent agent, string path, ConfigLoaderDelegate configLoader)
 2823      : base(agent) {
 1424    _relativePath = path;
 1425    _configLoader = configLoader;
 1426  }
 27
 28  // Initialize the interpolator.
 029  protected override void InitInterpolator() {
 030    string fileContent = _configLoader(_relativePath);
 031    if (string.IsNullOrEmpty(fileContent)) {
 032      throw new InvalidOperationException($"CSV file {_relativePath} is either null or empty.");
 33    }
 34
 035    string[] csvLines = fileContent.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
 036    string[] dataLines = csvLines.Where(line => !string.IsNullOrWhiteSpace(line)).ToArray();
 037    if (dataLines.Length < 1) {
 038      throw new InvalidOperationException(
 39          $"No data points available for interpolation in {_relativePath}.");
 40    }
 41
 042    try {
 043      _interpolator = new NearestNeighborInterpolator2D(dataLines);
 044    } catch (Exception e) {
 045      throw new InvalidOperationException(
 46          $"Failed to initialize interpolator from {_relativePath}.", e);
 47    }
 048  }
 49}