Skip to content

Commit

Permalink
Remove obsolete API methods
Browse files Browse the repository at this point in the history
This obviously introduces a breaking change
  • Loading branch information
eduherminio committed Nov 19, 2023
1 parent e728b81 commit ec7b8a5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 266 deletions.
258 changes: 0 additions & 258 deletions src/AoCHelper/Solver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,264 +252,6 @@ await AnsiConsole.Live(table)
RenderOverallResultsPanel(totalElapsedTime, configuration);
}

#region Obsolete

/// <summary>
/// Use <see cref="SolveLast(Action{SolverConfiguration}?)"/> instead
/// <example>
/// <code>
/// await Solver.SolveLast(opt => opt.ShowConstructorElapsedTime = true);
/// </code>
/// </example>
/// </summary>
/// <param name="configuration"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task SolveLast(SolverConfiguration? configuration)
{
configuration ??= new();
if (IsInteractiveEnvironment && configuration.ClearConsole)
{
AnsiConsole.Clear();
}

var table = GetTable();

await AnsiConsole.Live(table)
.AutoClear(false)
.Overflow(configuration.VerticalOverflow)
.Cropping(configuration.VerticalOverflowCropping)
.StartAsync(async ctx =>
{
var lastProblem = LoadAllProblems(Assembly.GetEntryAssembly()!).LastOrDefault();
if (lastProblem is not null)
{
var sw = new Stopwatch();
sw.Start();
var potentialProblem = Activator.CreateInstance(lastProblem);
sw.Stop();

if (potentialProblem is BaseProblem problem)
{
await SolveProblem(problem, table, CalculateElapsedMilliseconds(sw), configuration);
ctx.Refresh();
}
}
});
}

/// <summary>
/// Use <see cref="Solve{TProblem}(Action{SolverConfiguration}?)"/> instead
/// <example>
/// <code>
/// await Solver.Solve{Day01}(opt => opt.ShowConstructorElapsedTime = true);
/// </code>
/// </example>
/// </summary>
/// <typeparam name="TProblem"></typeparam>
/// <param name="configuration"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task Solve<TProblem>(SolverConfiguration? configuration)
where TProblem : BaseProblem, new()
{
configuration ??= new();
if (IsInteractiveEnvironment && configuration.ClearConsole)
{
AnsiConsole.Clear();
}

var table = GetTable();

await AnsiConsole.Live(table)
.AutoClear(false)
.Overflow(configuration.VerticalOverflow)
.Cropping(configuration.VerticalOverflowCropping)
.StartAsync(async ctx =>
{
var sw = new Stopwatch();
sw.Start();
TProblem problem = new();
sw.Stop();

await SolveProblem(problem, table, CalculateElapsedMilliseconds(sw), configuration);
ctx.Refresh();
});
}

/// <summary>
/// Use <see cref="Solve(Action{SolverConfiguration}?, uint[])"/> instead
/// <example>
/// <code>
/// await Solver.Solve(opt => opt.ShowConstructorElapsedTime = true, 1, 2);
/// </code>
/// </example>
/// </summary>
/// <param name="configuration"></param>
/// <param name="problemNumbers"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task Solve(SolverConfiguration? configuration, params uint[] problemNumbers)
=> await Solve(problemNumbers.AsEnumerable(), configuration);

/// <summary>
/// Use <see cref="Solve(Action{SolverConfiguration}?, Type[])"/> instead
/// <example>
/// <code>
/// await Solver.Solve(opt => opt.ShowConstructorElapsedTime = true, typeof(Problem66));
/// </code>
/// </example>
/// </summary>
/// <param name="configuration"></param>
/// <param name="problems"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task Solve(SolverConfiguration? configuration, params Type[] problems)
=> await Solve(problems.AsEnumerable(), configuration);

/// <summary>
/// Use <see cref="Solve(IEnumerable{uint}, Action{SolverConfiguration}?)"/> instead
/// <example>
/// <code>
/// await Solver.Solve(new uint[] { 1 }, opt => opt.ShowConstructorElapsedTime = true);
/// </code>
/// </example>
/// </summary>
/// <param name="problemNumbers"></param>
/// <param name="configuration"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task Solve(IEnumerable<uint> problemNumbers, SolverConfiguration? configuration)
{
configuration ??= new();
if (IsInteractiveEnvironment && configuration.ClearConsole)
{
AnsiConsole.Clear();
}

var totalElapsedTime = new List<ElapsedTime>();
var table = GetTable();

await AnsiConsole.Live(table)
.AutoClear(false)
.Overflow(configuration.VerticalOverflow)
.Cropping(configuration.VerticalOverflowCropping)
.StartAsync(async ctx =>
{
var sw = new Stopwatch();
foreach (Type problemType in LoadAllProblems(Assembly.GetEntryAssembly()!))
{
sw.Restart();
var potentialProblem = Activator.CreateInstance(problemType);
sw.Stop();

if (potentialProblem is BaseProblem problem && problemNumbers.Contains(problem.CalculateIndex()))
{
totalElapsedTime.Add(await SolveProblem(problem, table, CalculateElapsedMilliseconds(sw), configuration));
ctx.Refresh();
}
}
});

RenderOverallResultsPanel(totalElapsedTime, configuration);
}

/// <summary>
/// Use <see cref="Solve(IEnumerable{Type}, Action{SolverConfiguration}?)"/> instead
/// <example>
/// <code>
/// await Solver.Solve(new [] { typeof(Day10) }, opt => opt.ShowConstructorElapsedTime = true);
/// </code>
/// </example>
/// </summary>
/// <param name="problems"></param>
/// <param name="configuration"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task Solve(IEnumerable<Type> problems, SolverConfiguration? configuration)
{
configuration ??= new();
if (IsInteractiveEnvironment && configuration.ClearConsole)
{
AnsiConsole.Clear();
}

var totalElapsedTime = new List<ElapsedTime>();
var table = GetTable();

await AnsiConsole.Live(table)
.AutoClear(false)
.Overflow(configuration.VerticalOverflow)
.Cropping(configuration.VerticalOverflowCropping)
.StartAsync(async ctx =>
{
var sw = new Stopwatch();
foreach (Type problemType in LoadAllProblems(Assembly.GetEntryAssembly()!))
{
if (problems.Contains(problemType))
{
sw.Restart();
var potentialProblem = Activator.CreateInstance(problemType);
sw.Stop();

if (potentialProblem is BaseProblem problem)
{
totalElapsedTime.Add(await SolveProblem(problem, table, CalculateElapsedMilliseconds(sw), configuration));
ctx.Refresh();
}
}
}
});

RenderOverallResultsPanel(totalElapsedTime, configuration);
}

/// <summary>
/// Use <see cref="SolveAll(Action{SolverConfiguration}?)"/> instead
/// <example>
/// <code>
/// await Solver.SolveAll(options =>
/// {
/// options.ShowConstructorElapsedTime = true;
/// options.ShowOverallResults = true;
/// options.ClearConsole = false;
/// });
/// </code>
/// </example>
/// </summary>
/// <param name="configuration"></param>
[Obsolete("Use Action<SolverConfiguration>? overload instead")]
public static async Task SolveAll(SolverConfiguration? configuration)
{
configuration ??= new();
if (IsInteractiveEnvironment && configuration.ClearConsole)
{
AnsiConsole.Clear();
}

var totalElapsedTime = new List<ElapsedTime>();
var table = GetTable();

await AnsiConsole.Live(table)
.AutoClear(false)
.Overflow(configuration.VerticalOverflow)
.Cropping(configuration.VerticalOverflowCropping)
.StartAsync(async ctx =>
{
var sw = new Stopwatch();
foreach (Type problemType in LoadAllProblems(Assembly.GetEntryAssembly()!))
{
sw.Restart();
var potentialProblem = Activator.CreateInstance(problemType);
sw.Stop();

if (potentialProblem is BaseProblem problem)
{
totalElapsedTime.Add(await SolveProblem(problem, table, CalculateElapsedMilliseconds(sw), configuration));
ctx.Refresh();
}
}
});

RenderOverallResultsPanel(totalElapsedTime, configuration);
}

#endregion

/// <summary>
/// Loads all <see cref="BaseProblem"/> in the given assembly
/// </summary>
Expand Down
8 changes: 0 additions & 8 deletions tests/AoCHelper.Test/SolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,33 @@ public async Task Solve()
await Solver.Solve<Problem66>();
await Solver.Solve<Problem66>(_ => { });
await Solver.Solve<Problem66>(options: null);
await Solver.Solve<Problem66>(new SolverConfiguration());
}

[Fact]
public async Task SolveIntParams()
{
await Solver.Solve(options: null, 1, 2);
await Solver.Solve(new SolverConfiguration(), 1, 2);
}

[Fact]
public async Task SolveIntEnumerable()
{
await Solver.Solve(new List<uint> { 1, 2 });
await Solver.Solve(new List<uint> { 1, 2 }, _ => { });
await Solver.Solve(new List<uint> { 1, 2 }, new SolverConfiguration());
}

[Fact]
public async Task SolveTypeParams()
{
await Solver.Solve(_ => { }, typeof(Problem66));
await Solver.Solve(configuration: null, typeof(Problem66));
await Solver.Solve(options: null, typeof(Problem66));
await Solver.Solve(new SolverConfiguration(), typeof(Problem66));
}

[Fact]
public async Task SolveTypeEnumerable()
{
await Solver.Solve(new List<Type> { typeof(Problem66) });
await Solver.Solve(new List<Type> { typeof(Problem66) }, _ => { });
await Solver.Solve(new List<Type> { typeof(Problem66) }, new SolverConfiguration());
}

/// <summary>
Expand All @@ -100,7 +94,6 @@ public async Task SolveLast()
{
await Solver.SolveLast();
await Solver.SolveLast(_ => { });
await Solver.SolveLast(new SolverConfiguration());
}

/// <summary>
Expand All @@ -111,7 +104,6 @@ public async Task SolveAll()
{
await Solver.SolveAll();
await Solver.SolveAll(_ => { });
await Solver.SolveAll(new SolverConfiguration());
}

[Fact]
Expand Down

0 comments on commit ec7b8a5

Please sign in to comment.