| 1 | using CascadeIDE.Services.Presentation; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class PresentationZoneWeightsTests |
| 7 | { |
| 8 | [Fact] |
| 9 | public void TryNormalize_NoWeights_ReturnsEqualShares() |
| 10 | { |
| 11 | var screen = new[] |
| 12 | { |
| 13 | new PresentationAnchorSlot(PresentationAnchorKind.Pfd, null), |
| 14 | new PresentationAnchorSlot(PresentationAnchorKind.Forward, null), |
| 15 | new PresentationAnchorSlot(PresentationAnchorKind.Mfd, null), |
| 16 | }; |
| 17 | |
| 18 | var ok = PresentationZoneWeights.TryNormalize(screen, out var weights); |
| 19 | |
| 20 | Assert.True(ok); |
| 21 | Assert.Equal(3, weights.Count); |
| 22 | Assert.Equal(1.0 / 3.0, weights[0], 8); |
| 23 | Assert.Equal(1.0 / 3.0, weights[1], 8); |
| 24 | Assert.Equal(1.0 / 3.0, weights[2], 8); |
| 25 | } |
| 26 | |
| 27 | [Fact] |
| 28 | public void TryNormalize_WithWeights_NormalizesToOne() |
| 29 | { |
| 30 | var screen = new[] |
| 31 | { |
| 32 | new PresentationAnchorSlot(PresentationAnchorKind.Pfd, 0.6), |
| 33 | new PresentationAnchorSlot(PresentationAnchorKind.Forward, 0.3), |
| 34 | new PresentationAnchorSlot(PresentationAnchorKind.Mfd, 0.1), |
| 35 | }; |
| 36 | |
| 37 | var ok = PresentationZoneWeights.TryNormalize(screen, out var weights); |
| 38 | |
| 39 | Assert.True(ok); |
| 40 | Assert.Equal(3, weights.Count); |
| 41 | Assert.Equal(0.6, weights[0], 8); |
| 42 | Assert.Equal(0.3, weights[1], 8); |
| 43 | Assert.Equal(0.1, weights[2], 8); |
| 44 | Assert.Equal(1.0, weights[0] + weights[1] + weights[2], 8); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void MainGridDefinitions_UseNormalizedWeightedShares_ForTriple() |
| 49 | { |
| 50 | var parse = PresentationParseResult.Ok( |
| 51 | new[] |
| 52 | { |
| 53 | (IReadOnlyList<PresentationAnchorSlot>)new[] |
| 54 | { |
| 55 | new PresentationAnchorSlot(PresentationAnchorKind.Pfd, 0.5), |
| 56 | new PresentationAnchorSlot(PresentationAnchorKind.Forward, 0.3), |
| 57 | new PresentationAnchorSlot(PresentationAnchorKind.Mfd, 0.2), |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | var result = PresentationMainGridColumnDefinitions.Get( |
| 62 | parse, |
| 63 | dedicatedMfdSecondScreen: false, |
| 64 | mfdColumnSuppressedForHost: false, |
| 65 | tripleOneAnchorPerZone: false, |
| 66 | suppressPfdColumnForPfdHostWindow: false); |
| 67 | |
| 68 | Assert.Equal("0.5*,4,0.3*,4,0.2*", result); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |