Owner request 2026-11-06, items 3 and 4, with a screenshot of Compare. - Games (D85): Store, Engine, State, Installed and Played beside the search and sort, with Clear filters; the title counts what is shown of all while a filter or the search narrows it. Kept while the App runs, not saved. - Compare (D85): every session (it was the newest 200, one game lookup each; now one read of the names, off the UI thread), filtered by game, tier and frame generation, with a count; a ticked session stays listed. - Compare layout: the selection bar on the left above the list with Clear selection; columns sized to what they hold and one filler column; the date sorts by when; the settings-changed cell says so or shows a dash; the result table's labels sit over their columns (MetricHeader bound). - The pane (D86): our copy of WPF UI 4.3.0's LeftFluent item template without the IsActive collapse, so the selected page keeps its label. - Strings en/vi/ja (ja review); 08_UI, guide/07-screens, CHANGELOG, HANDOFF. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
264 lines
15 KiB
C#
264 lines
15 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using System.Globalization;
|
|
using FluentAssertions;
|
|
using FrameLedger.App.Charts;
|
|
using FrameLedger.App.Services;
|
|
using FrameLedger.App.ViewModels;
|
|
using FrameLedger.Application.Persistence;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
/// <summary>Compare over a scratch ledger: the picker's bounds, FR-6.2's guard gating a mixed selection, the curves for hooked sessions only, the table's best-value rule and its N/A cells.</summary>
|
|
[Collection(StringsCultureCollection.Name)]
|
|
public sealed class CompareViewModelTests
|
|
{
|
|
private sealed class ScriptedMixed(bool answer) : IMixedTierPrompt
|
|
{
|
|
public int Asked { get; private set; }
|
|
|
|
public Task<bool> AcknowledgeAsync(CancellationToken ct = default)
|
|
{
|
|
Asked++;
|
|
return Task.FromResult(answer);
|
|
}
|
|
}
|
|
|
|
private sealed class NoSaver : IFileSaver
|
|
{
|
|
public string? PickSavePath(string filter, string suggestedName) => null;
|
|
}
|
|
|
|
private sealed class NoStrip : IMessageStrip
|
|
{
|
|
public void Info(string title, string body)
|
|
{
|
|
}
|
|
|
|
public void Success(string title, string body)
|
|
{
|
|
}
|
|
|
|
public void Warn(string title, string body)
|
|
{
|
|
}
|
|
}
|
|
|
|
private static async Task<CompareViewModel> BuildAsync(ScratchLedger s, ScriptedMixed mixed)
|
|
{
|
|
var vm = new CompareViewModel(s.Library, new SessionSeriesLoader(s.Sessions), mixed, new NoSaver(), new NoStrip());
|
|
Task pending = vm.Pending;
|
|
await pending.ConfigureAwait(false);
|
|
return vm;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ThePickerNeedsTwoToFiveAndAMixedSelectionIsAQuestionFirst()
|
|
{
|
|
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
|
GameRow a = await s.GameAsync("Alpha");
|
|
GameRow b = await s.GameAsync("Beta");
|
|
await s.SessionWithFramesAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-3), frames: 300, spikeEvery: 0);
|
|
await s.SessionWithFramesAsync(b.Id, DateTimeOffset.UtcNow.AddHours(-2), frames: 300, spikeEvery: 50);
|
|
await s.SessionAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-1), hooked: false);
|
|
var mixed = new ScriptedMixed(answer: false);
|
|
CompareViewModel vm = await BuildAsync(s, mixed);
|
|
|
|
vm.IsEmpty.Should().BeFalse();
|
|
vm.Candidates.Should().HaveCount(3);
|
|
vm.CanCompare.Should().BeFalse("nothing picked");
|
|
vm.Candidates[0].IsSelected = true;
|
|
vm.CanCompare.Should().BeFalse("one is not a comparison");
|
|
vm.Candidates[1].IsSelected = true;
|
|
vm.CanCompare.Should().BeTrue();
|
|
vm.SelectedCount.Should().Be(2);
|
|
|
|
// a hooked + a not-hooked selection: the guard is asked, and a declined guard compares nothing
|
|
vm.Candidates[1].IsSelected = false; // the Tier-2 one (newest, index 0) stays picked, now with Alpha's hooked one
|
|
vm.Candidates[2].IsSelected = true;
|
|
vm.CompareCommand.Execute(null);
|
|
Task pending = vm.Pending;
|
|
await pending;
|
|
mixed.Asked.Should().Be(1);
|
|
vm.HasResult.Should().BeFalse("FR-6.2: no acknowledgement, no comparison");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnAcknowledgedMixedComparisonCarriesTheLegendAndKeepsTierTwoAtNa()
|
|
{
|
|
CultureInfo? previous = Strings.Culture;
|
|
Strings.Culture = CultureInfo.GetCultureInfo("en");
|
|
try
|
|
{
|
|
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
|
GameRow a = await s.GameAsync("Alpha");
|
|
await s.SessionWithFramesAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-3), frames: 300, spikeEvery: 0);
|
|
await s.SessionWithFramesAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-2), frames: 300, spikeEvery: 50);
|
|
await s.SessionAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-1), hooked: false,
|
|
shape: static r => r with { GameVramDedicatedMedianMb = 2048, GameVramDedicatedMaxMb = 3072, GameRamPrivateMedianMb = 1024, GameRamPrivateMaxMb = 1536 });
|
|
var mixed = new ScriptedMixed(answer: true);
|
|
CompareViewModel vm = await BuildAsync(s, mixed);
|
|
foreach (CompareCandidateViewModel c in vm.Candidates)
|
|
{
|
|
c.IsSelected = true;
|
|
}
|
|
|
|
vm.CompareCommand.Execute(null);
|
|
Task pending = vm.Pending;
|
|
await pending;
|
|
|
|
vm.HasResult.Should().BeTrue();
|
|
vm.IsMixed.Should().BeTrue();
|
|
vm.TierLegend.Should().Be(Strings.Compare_Mixed_Legend);
|
|
vm.Curves.Should().HaveCount(2, "a Tier-2 session has no frames and no curve");
|
|
vm.Compared.Should().HaveCount(3);
|
|
|
|
CompareRowViewModel median = vm.Rows.Single(r => string.Equals(r.Metric, "Median", StringComparison.Ordinal));
|
|
median.Cells[0].Text.Should().Be("N/A", "the newest, Tier 2, is first in the recent order");
|
|
median.Cells[0].IsBest.Should().BeFalse("N/A is never best");
|
|
median.Cells.Count(static c => c.IsBest).Should().Be(2, "both hooked sessions stored the same median, and a tie is best on both");
|
|
CompareRowViewModel temp = vm.Rows.Single(r => string.Equals(r.Metric, "Max GPU °C", StringComparison.Ordinal));
|
|
temp.Cells.Count(static c => c.IsBest).Should().BeGreaterThan(0, "lower is better and every row has 71 °C, so the ties are all best");
|
|
CompareRowViewModel presented = vm.Rows.Single(r => string.Equals(r.Metric, "Presented FPS", StringComparison.Ordinal));
|
|
presented.Cells.Should().OnlyContain(static c => c.Text == "N/A", "these sessions measured FG as none, so the Native row has them and this one does not");
|
|
CompareRowViewModel native = vm.Rows.Single(r => string.Equals(r.Metric, "Native FPS", StringComparison.Ordinal));
|
|
native.Cells.Skip(1).Should().OnlyContain(static c => c.Text == "60");
|
|
|
|
// beta.12: the game's memory is every session's — the Tier-2 one has it — and a fact, not a score: none is best.
|
|
CompareRowViewModel vramPeak = vm.Rows.Single(r => string.Equals(r.Metric, "Peak VRAM (game)", StringComparison.Ordinal));
|
|
vramPeak.Cells[0].Text.Should().Be(Formats.Memory(3072));
|
|
vramPeak.Cells.Skip(1).Should().OnlyContain(static c => c.Text == "N/A", "recorded without the game's memory");
|
|
vramPeak.Cells.Should().OnlyContain(static c => !c.IsBest);
|
|
vm.Rows.Single(r => string.Equals(r.Metric, "Median RAM (game)", StringComparison.Ordinal)).Cells[0].Text.Should().Be(Formats.Memory(1024));
|
|
|
|
// beta.10: the display rows are facts, not scores — none is best, and a row recorded before says N/A.
|
|
foreach (string metric in new[] { "Display mode", "Window", "Monitor" })
|
|
{
|
|
CompareRowViewModel display = vm.Rows.Single(r => string.Equals(r.Metric, metric, StringComparison.Ordinal));
|
|
display.Cells.Should().OnlyContain(static c => c.Text == "N/A" && !c.IsBest);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Strings.Culture = previous;
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TheBestOfARowIsTheHighestOrTheLowestAndNeverAnNa()
|
|
{
|
|
SessionRow[] rows =
|
|
[
|
|
new() { SessionGuid = Guid.NewGuid(), GameId = 1, SnapshotId = 1, StartedAt = DateTimeOffset.UnixEpoch, EndedAt = DateTimeOffset.UnixEpoch, QpcEpoch = 0, QpcFrequency = 1, Tier = Domain.Sessions.CaptureTier.Hooked, Mode = Domain.Sessions.CaptureMode.Launch, ExitStatus = Domain.Sessions.ExitStatus.Normal, MaxGpuTemp = 80 },
|
|
new() { SessionGuid = Guid.NewGuid(), GameId = 1, SnapshotId = 1, StartedAt = DateTimeOffset.UnixEpoch, EndedAt = DateTimeOffset.UnixEpoch, QpcEpoch = 0, QpcFrequency = 1, Tier = Domain.Sessions.CaptureTier.Hooked, Mode = Domain.Sessions.CaptureMode.Launch, ExitStatus = Domain.Sessions.ExitStatus.Normal, MaxGpuTemp = 65 },
|
|
new() { SessionGuid = Guid.NewGuid(), GameId = 1, SnapshotId = 1, StartedAt = DateTimeOffset.UnixEpoch, EndedAt = DateTimeOffset.UnixEpoch, QpcEpoch = 0, QpcFrequency = 1, Tier = Domain.Sessions.CaptureTier.NotHooked, Mode = Domain.Sessions.CaptureMode.Launch, ExitStatus = Domain.Sessions.ExitStatus.Normal, MaxGpuTemp = null },
|
|
];
|
|
|
|
CompareRowViewModel lower = CompareViewModel.Row("t", rows, static r => r.MaxGpuTemp, Formats.Temperature, higherIsBetter: false);
|
|
lower.Cells.Select(static c => c.IsBest).Should().Equal(false, true, false);
|
|
CompareRowViewModel higher = CompareViewModel.Row("t", rows, static r => r.MaxGpuTemp, Formats.Temperature, higherIsBetter: true);
|
|
higher.Cells.Select(static c => c.IsBest).Should().Equal(true, false, false);
|
|
CompareRowViewModel none = CompareViewModel.Row("t", rows, static _ => null, Formats.Temperature, higherIsBetter: true);
|
|
none.Cells.Should().OnlyContain(static c => !c.IsBest);
|
|
|
|
// beta.8: a load ranks nothing, and the best is the best as shown — 62.4 and 62.3 both read "62".
|
|
CompareViewModel.Row("t", rows, static r => r.MaxGpuTemp, Formats.Temperature, higherIsBetter: null).Cells.Should().OnlyContain(static c => !c.IsBest);
|
|
SessionRow[] close = [rows[0] with { MedianFps = 62.4 }, rows[1] with { MedianFps = 62.3 }, rows[2] with { MedianFps = 55 }];
|
|
CompareViewModel.Row("t", close, static r => r.MedianFps, static v => Formats.FpsNumber(v!.Value, twoDecimals: false), higherIsBetter: true)
|
|
.Cells.Select(static c => c.IsBest).Should().Equal([true, true, false], "both are shown as 62");
|
|
}
|
|
/// <summary>
|
|
/// beta.14 (D49): the new rows, and the <c>(presented)</c> label — a session whose frame statistics are over its presents
|
|
/// says so in its cell, beside one whose statistics are over the game's own frames (rule 6). The best is decided on the
|
|
/// number: less time below 60 is better, more frames per watt is better, and a VSync share ranks nothing.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task APresentOnlySessionsStatisticsAreLabelledAndTheNewRowsRankAsTheySay()
|
|
{
|
|
CultureInfo? previous = Strings.Culture;
|
|
CultureInfo previousCulture = CultureInfo.CurrentCulture;
|
|
Strings.Culture = CultureInfo.GetCultureInfo("en");
|
|
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en");
|
|
try
|
|
{
|
|
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
|
GameRow a = await s.GameAsync("Alpha");
|
|
await s.SessionAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-2), fgMode: "na", native: null, presented: 72, qualifier: "fg_runtime_loaded",
|
|
shape: static r => r with { TimeBelow60Pct = 20, VsyncPresentPct = 100, AppFramesPerJoule = null, UpscaleRatio = 1.5 });
|
|
await s.SessionAsync(a.Id, DateTimeOffset.UtcNow.AddHours(-1),
|
|
shape: static r => r with { TimeBelow60Pct = 5, VsyncPresentPct = 0, AppFramesPerJoule = 0.31, UpscaleRatio = 2 });
|
|
CompareViewModel vm = await BuildAsync(s, new ScriptedMixed(answer: true));
|
|
foreach (CompareCandidateViewModel c in vm.Candidates)
|
|
{
|
|
c.IsSelected = true;
|
|
}
|
|
|
|
vm.CompareCommand.Execute(null);
|
|
Task pending = vm.Pending;
|
|
await pending;
|
|
CompareRowViewModel RowOf(string metric) => vm.Rows.Single(r => string.Equals(r.Metric, metric, StringComparison.Ordinal));
|
|
|
|
// Newest first: the counted-none session, then the present-only one.
|
|
RowOf("1% Low").Cells.Select(static c => c.Text).Should().Equal("48", "48 (presented)");
|
|
CompareRowViewModel below = RowOf("Time below 60 FPS");
|
|
below.Cells.Select(static c => c.Text).Should().Equal("5.0%", "20.0% (presented)");
|
|
below.Cells.Select(static c => c.IsBest).Should().Equal(true, false);
|
|
RowOf("Frames per watt").Cells.Select(static c => (c.Text, c.IsBest)).Should().Equal(("0.31 FPS/W", true), ("N/A", false));
|
|
RowOf("VSync share").Cells.Should().OnlyContain(static c => !c.IsBest, "a setting, not a score");
|
|
RowOf("Render scale").Cells.Select(static c => c.Text).Should().Equal("50.0%", "66.7%");
|
|
}
|
|
finally
|
|
{
|
|
Strings.Culture = previous;
|
|
CultureInfo.CurrentCulture = previousCulture;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// beta.34 (owner request 2026-11-06, D85): Compare lists every session — it was the newest 200 — and filters them by game,
|
|
/// tier and frame generation; a ticked session stays listed whatever the filters say, and the count says how many of how
|
|
/// many are shown.
|
|
/// </summary>
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1863:Use 'CompositeFormat'", Justification = "the format strings are resources that follow the UI culture")]
|
|
[Fact]
|
|
public async Task TheFiltersNarrowTheListAndATickedSessionStaysOnIt()
|
|
{
|
|
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
|
GameRow a = await s.GameAsync("Alpha");
|
|
GameRow b = await s.GameAsync("Beta");
|
|
DateTimeOffset now = DateTimeOffset.UtcNow;
|
|
_ = await s.SessionAsync(a.Id, now.AddHours(-5), fgMode: "dlssg", native: 60, displayed: 180, factor: 3);
|
|
_ = await s.SessionAsync(a.Id, now.AddHours(-4), fgMode: "none");
|
|
_ = await s.SessionAsync(b.Id, now.AddHours(-3), fgMode: "none");
|
|
_ = await s.SessionAsync(b.Id, now.AddHours(-2), hooked: false);
|
|
CompareViewModel vm = await BuildAsync(s, new ScriptedMixed(answer: true));
|
|
|
|
vm.Candidates.Should().HaveCount(4);
|
|
vm.CountText.Should().Be(string.Format(CultureInfo.CurrentCulture, Strings.Compare_Count_Format, 4));
|
|
vm.Games.Select(static g => g.Label).Should().Equal([Strings.Compare_Filter_Game_All, "Alpha", "Beta"]);
|
|
|
|
vm.GameFilter = a.Id;
|
|
vm.Candidates.Should().HaveCount(2).And.OnlyContain(c => c.GameId == a.Id);
|
|
vm.CountText.Should().Be(string.Format(CultureInfo.CurrentCulture, Strings.Compare_Count_Filtered_Format, 2, 4));
|
|
|
|
vm.FrameGenerationFilter = YesNoFilter.Yes;
|
|
vm.Candidates.Should().ContainSingle().Which.HasFrameGeneration.Should().BeTrue();
|
|
vm.Candidates[0].IsSelected = true;
|
|
|
|
vm.GameFilter = b.Id;
|
|
vm.FrameGenerationFilter = YesNoFilter.All;
|
|
vm.TierFilter = CompareTierFilter.NotMeasured;
|
|
vm.Candidates.Should().HaveCount(2, "Beta's unmeasured session, and the ticked one, which a filter never hides");
|
|
vm.Candidates.Count(static c => c.IsSelected).Should().Be(1);
|
|
vm.SelectedCount.Should().Be(1);
|
|
|
|
vm.ClearSelectionCommand.Execute(null);
|
|
vm.SelectedCount.Should().Be(0);
|
|
vm.ClearFiltersCommand.Execute(null);
|
|
vm.Candidates.Should().HaveCount(4);
|
|
vm.Candidates.Single(static c => c.HasFrameGeneration is null).TierText.Should().Be(Strings.Tier_NotHooked);
|
|
vm.Candidates.Should().OnlyContain(static c => c.SettingsChangedText.Length > 0, "a dash where nothing changed — the column was blank");
|
|
}
|
|
}
|