Files
ParkingRobot/ClumsyPilot/tests/EMPlannerVerificationHost/FakeQpSolver.cs
T

40 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using MultiWheelC.TrajectoryPlanning.EMPlanner;
namespace EMPlannerVerificationHost;
internal sealed class FakeQpSolver : IQpSolver
{
private readonly QpSolveResult _result;
public FakeQpSolver(QpSolveResult result)
{
_result = result ?? throw new ArgumentNullException(nameof(result));
LastWarmStart = Array.Empty<double>();
}
public QuadraticProgram? LastProblem { get; private set; }
public QpSolverSettings? LastSettings { get; private set; }
public IReadOnlyList<double> LastWarmStart { get; private set; }
public QpSolveResult Solve(QuadraticProgram problem, QpSolverSettings settings, IReadOnlyList<double> warmStart,
CancellationToken cancellationToken)
{
LastProblem = problem ?? throw new ArgumentNullException(nameof(problem));
LastSettings = settings ?? throw new ArgumentNullException(nameof(settings));
var copy = new List<double>(warmStart == null ? 0 : warmStart.Count);
if (warmStart != null)
{
for (int index = 0; index < warmStart.Count; index++)
copy.Add(warmStart[index]);
}
LastWarmStart = new ReadOnlyCollection<double>(copy);
return _result;
}
}