|
| 1 | +namespace StaticSeries; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Tests for the obsolete v3 <c>GetPvo</c> shim, which must return what the pre-3.0.0 |
| 5 | +/// API returned. |
| 6 | +/// </summary> |
| 7 | +/// <remarks> |
| 8 | +/// The shim declared <c>9, 12, 9</c> where both v2 and <c>ToPvo</c> declare |
| 9 | +/// <c>12, 26, 9</c> — the correct values shifted one position. Calling the documented |
| 10 | +/// default therefore computed a different indicator, silently: the result is a |
| 11 | +/// well-formed PVO, just not the one asked for. Nothing here called the shim, so |
| 12 | +/// nothing caught it. |
| 13 | +/// </remarks> |
| 14 | +[TestClass] |
| 15 | +public class PvoObsoleteShimTests : TestBaseWithPrecision |
| 16 | +{ |
| 17 | + [TestMethod] |
| 18 | + public void GetPvoDefaultsMatchToPvo() |
| 19 | + { |
| 20 | +#pragma warning disable CS0618 // exercising the obsolete shim is the point |
| 21 | + List<PvoResult> shim = Bars.GetPvo().ToList(); |
| 22 | +#pragma warning restore CS0618 |
| 23 | + |
| 24 | + IReadOnlyList<PvoResult> expected = Bars.ToPvo(); |
| 25 | + |
| 26 | + shim.Should().HaveCount(expected.Count); |
| 27 | + shim.Select(static r => r.Pvo).Should().Equal(expected.Select(static r => r.Pvo)); |
| 28 | + shim.Select(static r => r.Signal).Should().Equal(expected.Select(static r => r.Signal)); |
| 29 | + shim.Select(static r => r.Histogram).Should().Equal(expected.Select(static r => r.Histogram)); |
| 30 | + } |
| 31 | + |
| 32 | + [TestMethod] |
| 33 | + public void GetPvoDefaultsAreNotTheShiftedPeriods() |
| 34 | + { |
| 35 | + // guards the specific 3.0.0 regression: the shim declared 9, 12, 9 |
| 36 | +#pragma warning disable CS0618 |
| 37 | + List<PvoResult> shim = Bars.GetPvo().ToList(); |
| 38 | +#pragma warning restore CS0618 |
| 39 | + |
| 40 | + IReadOnlyList<PvoResult> shifted = Bars.ToPvo(9, 12, 9); |
| 41 | + |
| 42 | + shim[^1].Pvo.Should().NotBeApproximately(shifted[^1].Pvo!.Value, Money6); |
| 43 | + } |
| 44 | + |
| 45 | + [TestMethod] |
| 46 | + public void GetPvoMatchesKnownValues() |
| 47 | + { |
| 48 | + // anchors the shim to absolute values, so a co-regression in ToPvo cannot |
| 49 | + // move both sides of the comparison above and pass unnoticed |
| 50 | +#pragma warning disable CS0618 |
| 51 | + List<PvoResult> shim = Bars.GetPvo().ToList(); |
| 52 | +#pragma warning restore CS0618 |
| 53 | + |
| 54 | + shim.Should().HaveCount(502); |
| 55 | + shim[501].Pvo.Should().BeApproximately(10.439509, Money6); |
| 56 | + } |
| 57 | + |
| 58 | + [TestMethod] |
| 59 | + public void GetPvoWithExplicitPeriodsMatchesToPvo() |
| 60 | + { |
| 61 | +#pragma warning disable CS0618 |
| 62 | + List<PvoResult> shim = Bars.GetPvo(10, 20, 7).ToList(); |
| 63 | +#pragma warning restore CS0618 |
| 64 | + |
| 65 | + IReadOnlyList<PvoResult> expected = Bars.ToPvo(10, 20, 7); |
| 66 | + |
| 67 | + shim.Select(static r => r.Pvo).Should().Equal(expected.Select(static r => r.Pvo)); |
| 68 | + } |
| 69 | +} |
0 commit comments