Skip to content

Commit

Permalink
test: stabilize When_RepeatForever_ShouldLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Apr 5, 2023
1 parent 3491c17 commit 625e055
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -138,13 +139,10 @@ public async Task When_RepeatForever_ShouldLoop()
To = 50,
RepeatBehavior = RepeatBehavior.Forever,
Duration = TimeSpan.FromMilliseconds(500),
};
Storyboard.SetTarget(animation, target);
Storyboard.SetTargetProperty(animation, nameof(Rectangle.Width));

var storyboard = new Storyboard { Children = { animation } };
storyboard.Begin();
}.BindTo(target, nameof(Rectangle.Width));
animation.Begin();

// In an ideal world, the measurements would be [0,10,20,30,40] repeated 10 times.
var list = new List<double>();
for (int i = 0; i < 50; i++)
{
Expand All @@ -160,10 +158,12 @@ public async Task When_RepeatForever_ShouldLoop()
.ToArray();
var incrementSizes = drops.Zip(drops.Skip(1), (a, b) => b - a - 1).ToArray(); // -1 to exclude the drop itself

Trace.WriteLine($"values: {string.Join(',', list)}");

// This 500ms animation is expected to climb from 0 to 50, reset to 0 instantly, and repeat forever.
// Given that we are taking 5measurements per cycle, we can expect the followings:
Assert.AreEqual(10d, averageIncrement, 1.5, "an rough average of increment (exluding the drop) of 10 (+-15% error margin)");
Assert.IsTrue(incrementSizes.Count(x => x > 3) > 8, $"at least 10 (-2 error margin: might miss first and/or last) sets of continuous increments that size of 4 (+-1 error margin: sliding slot): {string.Join(",", incrementSizes)}");
Assert.AreEqual(10d, averageIncrement, 2.5, $"Expected an rough average of increment (excluding the drop) of 10 (+-25% error margin): [{string.Join(",", delta)}]");
Assert.IsTrue(incrementSizes.Count(x => x >= 3) >= 8, $"Expected at least 10sets (-2 error margin: might miss first and/or last) of continuous increments in size of 4 (+-1 error margin: sliding slot): {string.Join(",", incrementSizes)}");
}

[TestMethod]
Expand Down

0 comments on commit 625e055

Please sign in to comment.