using Xunit; using ytLive.Helpers; namespace ytLive.Tests; /// The dock's faders speak dB while the model stores linear gain, so the mapping is load /// bearing: get it wrong and every reported level is wrong by a constant. Unity, the floor and /// the +6 dB ceiling are the three values a creator actually checks. public class GainDbTests { [Fact] public void Db_and_linear_gain_round_trip_and_the_ends_are_honest() { // Unity is the anchor: 1.0 ↔ 0 dB, and the default mic volume reads −1.9 dB. Assert.Equal(0, GainDb.ToDb(1.0), 6); Assert.Equal(1.0, GainDb.FromDb(0), 6); Assert.Equal(-1.9, GainDb.ToDb(0.8), 1); // Halving is −6 dB — the number a creator reads as "half". Assert.Equal(-6.02, GainDb.ToDb(0.5), 1); // The floor is TRUE silence: no residue left at the bottom of the fader. Assert.Equal(0.0, GainDb.FromDb(GainDb.FloorDb)); Assert.Equal(0.0, GainDb.FromDb(-999)); // Ceiling: +6 dB is twice the amplitude and nothing beyond it. Assert.Equal(2.0, GainDb.FromDb(6), 2); Assert.Equal(6, GainDb.ToDb(GainDb.FromDb(99)), 6); // Round-trip across the usable range. foreach (var db in new[] { -60.0, -40, -20, -12, -6, -3, 0, 3, 6 }) Assert.Equal(db, GainDb.ToDb(GainDb.FromDb(db)), 6); // Labels are what the creator reads. Assert.Equal("−∞", GainDb.Label(GainDb.FloorDb)); Assert.Equal("-6.0", GainDb.Label(-6)); Assert.Equal("+1.5", GainDb.Label(1.5)); // The mono fold: a hard-right signal becomes audible on the left at half amplitude. Assert.Equal(0.25f, GainDb.MonoFold(0f, 0.5f)); Assert.Equal(0.5f, GainDb.MonoFold(0.5f, 0.5f)); } }