Snapshot Interpolation tests: check local timeline and fail early to prepare for clamping

This commit is contained in:
vis2k 2023-03-11 10:02:19 +08:00
parent 712032a0aa
commit 67aa480fdd

View File

@ -220,8 +220,13 @@ public void Insert_ComputesAverageDrift()
// insert in order
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
// first insertion initializes localTime to '2'.
// so the timediffs to '2' are: 0, 1, 3.
@ -246,8 +251,13 @@ public void Insert_ComputesAverageDrift_Scrambled()
// insert scrambled (not in order)
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
// first insertion initializes localTime to '2'.
// so the timediffs to '2' are: 0, 3, 1.
@ -277,8 +287,13 @@ public void Insert_ComputesAverageDeliveryInterval()
// insert in order
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
// first insertion doesn't compute delivery interval because we need 2 snaps.
// second insertion computes 4-3 = 1
@ -308,8 +323,14 @@ public void Insert_ComputesAverageDeliveryInterval_Scrambled()
// insert in order
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(2)); // detect wrong timeline immediately
// first insertion doesn't compute delivery interval because we need 2 snaps.
// second insertion computes 4-3 = 1
@ -334,9 +355,15 @@ public void Sample()
SimpleSnapshot a = new SimpleSnapshot(10, 0, 42);
SimpleSnapshot b = new SimpleSnapshot(20, 0, 43);
SimpleSnapshot c = new SimpleSnapshot(30, 0, 44);
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
// sample at a time before the first snapshot
SnapshotInterpolation.Sample(buffer, 9, out int from, out int to, out double t);
@ -373,8 +400,13 @@ public void Step()
SimpleSnapshot c = new SimpleSnapshot(30, 0, 44);
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
// step half way to the next snapshot
SnapshotInterpolation.Step(buffer, 5, ref localTimeline, localTimescale, out SimpleSnapshot fromSnapshot, out SimpleSnapshot toSnapshot, out double t);
@ -398,8 +430,13 @@ public void Step_RemovesOld()
SimpleSnapshot c = new SimpleSnapshot(30, 0, 44);
SnapshotInterpolation.InsertAndAdjust(buffer, a, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, b, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
SnapshotInterpolation.InsertAndAdjust(buffer, c, ref localTimeline, ref localTimescale, 0, 0, 0.01, 0.01, ref driftEma, 0, 0, ref deliveryIntervalEma);
Assert.That(localTimeline, Is.EqualTo(10)); // detect wrong timeline immediately
// step 1.5 snapshots worth, so way past the first one
SnapshotInterpolation.Step(buffer, 15, ref localTimeline, localTimescale, out SimpleSnapshot fromSnapshot, out SimpleSnapshot toSnapshot, out double t);