mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 17:57:57 +01:00
* Fixed MouseGrabView bug. Added extensive test coverage for `Keyboard`, `Mouse`, `Timeout`, and `Popover` functionalities, including edge cases and concurrent access. Introduced parameterized and data-driven tests to reduce redundancy and improve clarity. Refactored codebase for modularity and maintainability, introducing new namespaces and reorganizing classes. Enhanced `MouseImpl`, `KeyboardImpl`, and `Runnable` implementations with improved event handling, thread safety, and support for the Terminal.Gui Cancellable Work Pattern (CWP). Removed deprecated code and legacy tests, such as `LogarithmicTimeout` and `SmoothAcceleratingTimeout`. Fixed bugs related to mouse grabbing during drag operations and unbalanced `ApplicationImpl.Begin/End` calls. Improved documentation and code readability with modern C# features. * Code cleanup. * Update Tests/UnitTestsParallelizable/Application/Runnable/RunnableIntegrationTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improve null handling and simplify test setup In `MouseImpl.cs`, added an early `return` after the `UngrabMouse()` call within the `if (view is null)` block to prevent further execution when `view` is `null`, improving null reference handling. In `RunnableIntegrationTests.cs`, removed the initialization of the `IApplication` object (`app`) from the `MultipleRunnables_IndependentResults` test method, simplifying the test setup and focusing on runnable behavior. * Code cleanup * API doc link cleanup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
namespace ApplicationTests.Timeout;
|
||||
|
||||
public class SmoothAcceleratingTimeoutTests
|
||||
{
|
||||
[Fact]
|
||||
public void Span_Should_Return_InitialDelay_On_StageZero ()
|
||||
{
|
||||
var initialDelay = TimeSpan.FromMilliseconds (500);
|
||||
var minDelay = TimeSpan.FromMilliseconds (50);
|
||||
double decayFactor = 0.7;
|
||||
|
||||
var timeout = new SmoothAcceleratingTimeout (initialDelay, minDelay, decayFactor, () => true);
|
||||
|
||||
Assert.Equal (initialDelay, timeout.Span);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Span_Should_Decrease_As_Stage_Increases ()
|
||||
{
|
||||
var initialDelay = TimeSpan.FromMilliseconds (500);
|
||||
var minDelay = TimeSpan.FromMilliseconds (50);
|
||||
double decayFactor = 0.7;
|
||||
|
||||
var timeout = new SmoothAcceleratingTimeout (initialDelay, minDelay, decayFactor, () => true);
|
||||
|
||||
var previousSpan = timeout.Span;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
timeout.AdvanceStage ();
|
||||
var currentSpan = timeout.Span;
|
||||
Assert.True (currentSpan <= previousSpan, $"Stage {i + 1}: {currentSpan} should be <= {previousSpan}");
|
||||
previousSpan = currentSpan;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Span_Should_Not_Go_Below_MinDelay ()
|
||||
{
|
||||
var initialDelay = TimeSpan.FromMilliseconds (500);
|
||||
var minDelay = TimeSpan.FromMilliseconds (50);
|
||||
double decayFactor = 0.5;
|
||||
|
||||
var timeout = new SmoothAcceleratingTimeout (initialDelay, minDelay, decayFactor, () => true);
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
timeout.AdvanceStage ();
|
||||
}
|
||||
|
||||
Assert.Equal (minDelay, timeout.Span);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_Should_Set_Stage_Back_To_Zero ()
|
||||
{
|
||||
var initialDelay = TimeSpan.FromMilliseconds (500);
|
||||
var minDelay = TimeSpan.FromMilliseconds (50);
|
||||
double decayFactor = 0.7;
|
||||
|
||||
var timeout = new SmoothAcceleratingTimeout (initialDelay, minDelay, decayFactor, () => true);
|
||||
|
||||
timeout.AdvanceStage ();
|
||||
timeout.AdvanceStage ();
|
||||
Assert.NotEqual (initialDelay, timeout.Span);
|
||||
|
||||
timeout.Reset ();
|
||||
Assert.Equal (initialDelay, timeout.Span);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user