-
Notifications
You must be signed in to change notification settings - Fork 283
feat(tests): add continuity and stability tests for Synchronous mode … #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mariborges22
wants to merge
1
commit into
RawAccelOfficial:master
Choose a base branch
from
mariborges22:test/wrapper-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace wrapper_tests | ||
| { | ||
| [TestClass] | ||
| public class ThresholdTests | ||
| { | ||
| /// <summary> | ||
| /// This test checks for "jumps" in output when crossing the sharpness = 16 threshold. | ||
| /// It compares the Driver's optimized logic (which clamps at 16) with a | ||
| /// pure mathematical simulator that does NOT clamp. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void SynchronousAccel_ThresholdCrossing_IsContinuous() | ||
| { | ||
| double syncSpeed = 20; | ||
| double gamma = 0.5; | ||
| double motivity = 1.3; | ||
|
|
||
| // smooth = 0.03125 exactly results in sharpness = 16 | ||
| // We test values slightly above and slightly below this threshold | ||
| double[] smoothValues = { 0.03126, 0.03125, 0.03124, 0.0 }; | ||
|
|
||
| foreach (double smooth in smoothValues) | ||
| { | ||
| var profile = new Profile(); | ||
| profile.outputDPI = 1000; | ||
| profile.argsX.mode = AccelMode.synchronous; | ||
| profile.argsX.gain = false; | ||
| profile.argsX.syncSpeed = syncSpeed; | ||
| profile.argsX.gamma = gamma; | ||
| profile.argsX.motivity = motivity; | ||
| profile.argsX.smooth = smooth; | ||
|
|
||
| var accel = new ManagedAccel(profile); | ||
|
|
||
| // Pure Math Simulator (Ignores the 16 threshold) | ||
| var pureSimulator = new UnclampedSynchronousSimulator(syncSpeed, motivity, gamma, smooth); | ||
|
|
||
| // Test with various input counts (1 to 100) | ||
| for (int input = 1; input < 100; input += 5) | ||
| { | ||
| Tuple<double, double> output = accel.Accelerate(input, 0, 1, 10); | ||
|
|
||
| double inputSpeed = (double)input / 10.0; | ||
| double expectedOutput = (double)input * pureSimulator.Accelerate(inputSpeed); | ||
|
|
||
| // We expect the difference to be very small (continuity check) | ||
| // Precision of 0.01% is usually safe for mouse input | ||
| double delta = Math.Abs(output.Item1 - expectedOutput); | ||
| double relativeError = delta / expectedOutput; | ||
|
|
||
| Assert.IsTrue(relativeError < 0.001, | ||
| $"Discontinuity found at smooth={smooth}, input={input}. " + | ||
| $"Driver: {output.Item1}, Pure Math: {expectedOutput}, Error: {relativeError:P}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A simulator that follows the raw math WITHOUT the sharpness >= 16 optimization. | ||
| /// This allows us to see what the "true" curve would look like without the clamp. | ||
| /// </summary> | ||
| public class UnclampedSynchronousSimulator | ||
| { | ||
| public UnclampedSynchronousSimulator(double syncSpeed, double motivity, double gamma, double smooth) | ||
| { | ||
| SyncSpeed = syncSpeed; | ||
| Motivity = motivity; | ||
| Gamma = gamma; | ||
| Sharpness = smooth <= 0 ? 100 : 0.5 / smooth; // Use a very high number instead of clamping | ||
| } | ||
|
|
||
| public double SyncSpeed { get; } | ||
| public double Motivity { get; } | ||
| public double Gamma { get; } | ||
| public double Sharpness { get; } | ||
|
|
||
| public double Accelerate(double inputSpeed) | ||
| { | ||
| if (inputSpeed == SyncSpeed) return 1.0; | ||
|
|
||
| double logSyncSpeed = Math.Log(SyncSpeed); | ||
| double logMotivity = Math.Log(Motivity); | ||
| double gammaConst = Gamma / logMotivity; | ||
|
|
||
| double logX = Math.Log(inputSpeed); | ||
| double logDiff = logX - logSyncSpeed; | ||
|
|
||
| double logSpace = Math.Abs(gammaConst * logDiff); | ||
| double exponent = Math.Pow(Math.Tanh(Math.Pow(logSpace, Sharpness)), 1 / Sharpness); | ||
|
|
||
| if (logDiff < 0) exponent = -exponent; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exponent *= Math.Sign(logDiff) is clearer phrasing |
||
|
|
||
| return Math.Exp(exponent * logMotivity); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ | |
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| <Compile Include="SpeedTests.cs" /> | ||
| <Compile Include="SynchronousAccelTests.cs" /> | ||
| <Compile Include="ThresholdTests.cs" /> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move tests to SynchronousAccelTests and remove this |
||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="packages.config" /> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go in SynchronousAccelTests.