38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using NUnit.Framework;
|
|
using CeresSharp;
|
|
|
|
namespace CeresSharp.Test;
|
|
|
|
/// <summary>
|
|
/// Base class for tests with proper cleanup
|
|
/// </summary>
|
|
public abstract class TestBase
|
|
{
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
// Small delay to ensure native cleanup is complete before next test
|
|
// This helps prevent crash when running multiple tests
|
|
// Note: Don't force GC here as it may cause crash in finalizer thread
|
|
System.Threading.Thread.Sleep(5);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Helper method to solve a problem with exception handling.
|
|
/// Returns null if solve fails (expected in some cases).
|
|
/// </summary>
|
|
protected SolverSummary? TrySolve(Problem problem, SolverOptions options)
|
|
{
|
|
try
|
|
{
|
|
return problem.Solve(options);
|
|
}
|
|
catch (Exceptions.CeresException ex)
|
|
{
|
|
// Expected for some problems - just log and return null
|
|
Console.WriteLine($"Solve failed (expected in some cases): {ex.Message}");
|
|
return null;
|
|
}
|
|
}
|
|
}
|