using System;

namespace TrajectoryPlanningVisualizationVerificationHost;

internal static class Verification
{
    public static void Equal<T>(T expected, T actual, string message)
    {
        if (!Equals(expected, actual))
        {
            throw new InvalidOperationException(message + ": expected " + expected + ", actual " + actual);
        }
    }

    public static void NearlyEqual(double expected, double actual, string message)
    {
        if (Math.Abs(expected - actual) > 0.0000001d)
        {
            throw new InvalidOperationException(message + ": expected " + expected + ", actual " + actual);
        }
    }

    public static void True(bool value, string message)
    {
        if (!value)
        {
            throw new InvalidOperationException(message);
        }
    }

    public static void Throws<TException>(Action action, string message)
        where TException : Exception
    {
        try
        {
            action();
        }
        catch (TException)
        {
            return;
        }

        throw new InvalidOperationException(message);
    }
}
