diff --git a/changelog.d/+sandsack-rechenweg.added.md b/changelog.d/+sandsack-rechenweg.added.md new file mode 100644 index 0000000..3b0240a --- /dev/null +++ b/changelog.d/+sandsack-rechenweg.added.md @@ -0,0 +1 @@ +The Sandsack helper now explains below its result how each Richtwert is calculated, with the values entered, including why it plans with wet sand at 2,0 t/m³ rather than dry sand at 1,2 to 1,6 t/m³ (#87). diff --git a/docs/play/screenshots/21-sandsack.png b/docs/play/screenshots/21-sandsack.png index 68e1f79..25f3243 100644 Binary files a/docs/play/screenshots/21-sandsack.png and b/docs/play/screenshots/21-sandsack.png differ diff --git a/docs/screenshots/21-sandsack.png b/docs/screenshots/21-sandsack.png index 78841ac..e11a3f7 100644 Binary files a/docs/screenshots/21-sandsack.png and b/docs/screenshots/21-sandsack.png differ diff --git a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack.Ui/SandsackView.axaml b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack.Ui/SandsackView.axaml index 76f884a..fdd5ddc 100644 --- a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack.Ui/SandsackView.axaml +++ b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack.Ui/SandsackView.axaml @@ -13,7 +13,9 @@ - + + @@ -28,6 +30,22 @@ + + + + + + + + + + + + + + + + +/// How the Sandsack helper gets to its Richtwerte, one German line per step, for the screen (#87). +/// Each line shows the rule, and once the values it needs are entered, it shows the user's own +/// numbers worked through. Every figure comes from , and every +/// result comes from . The text cannot drift from the arithmetic. +/// +public static class SandsackRechenweg +{ + private static readonly string Stufen = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.HoeheMeter)); + + private static readonly string SaeckeJeMeter = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.SaeckeJeMeter)); + + private static readonly string SandJeMeter = Liste(Sandsackvorgaben.Dammstufen.Select(s => s.SandKubikmeterJeMeter)); + + private static readonly string Nass = Formatting.Number(Sandsackvorgaben.SandTonnenJeKubikmeter, 1); + + private static readonly string TrockenMin = Formatting.Number(Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter, 1); + + private static readonly string TrockenMax = Formatting.Number(Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter, 1); + + private static readonly string Arbeitsgaenge = Formatting.Number(Sandsackvorgaben.ArbeitsgaengeJeSack); + + private static readonly string Leistung = Formatting.Number(Sandsackvorgaben.SaeckeJeHelferUndStunde, 0); + + private static readonly string Basisfaktor = Formatting.Number(Sandsackvorgaben.BasisbreiteJeHoehe, 0); + + private static readonly string WarumNass = + $"Nasser Sand wiegt bis zu {Formatting.Number(SandsackRechner.NassMehrgewichtProzent, 0)} % mehr als trockener. " + + "Gerechnet wird mit nassem Sand, damit Ladung und Fahrten reichen."; + + /// Why every result errs towards too much. + public const string SichereSeite = + "Zur sicheren Seite gerechnet: Säcke „quer verlegt“, der obere Sandwert " + + "und die langsamste Arbeitsleistung der Taschenkarte."; + + /// + /// The steps, in the order the results are shown. A value that is has + /// not been entered, or is not valid, and its steps show the rule alone. + /// + public static IReadOnlyList Zeilen(decimal? laengeMeter, decimal? hoeheMeter, decimal? helfer) + { + if (hoeheMeter is not { } hoehe) + { + return + [ + $"Höhe: aufgerundet auf die nächste Stufe der Tabelle, {Stufen} m.", + $"Sandsäcke: Länge × Säcke je m der Stufe ({SaeckeJeMeter}), aufgerundet.", + $"Sand: Länge × m³ je m der Stufe ({SandJeMeter}), aufgerundet auf 0,1 m³.", + $"Sand, nass: m³ × {Nass} t/m³.", + $"Sand, trocken: {TrockenMin} bis {TrockenMax} t/m³. {WarumNass}", + $"Arbeitszeit: Säcke × {Arbeitsgaenge} Arbeitsgänge (Füllen und Tragen, Verlegen) ÷ {Leistung} Säcke " + + "je Helfer und Stunde ÷ Helfer, aufgerundet auf die Viertelstunde. Nur ganze Helfer zählen.", + $"Basisbreite: Höhe × {Basisfaktor}.", + SichereSeite, + ]; + } + + var stufe = SandsackRechner.Stufe(hoehe); + var basis = SandsackRechner.Basisbreite(hoehe); + var hoeheZeile = $"Höhe: {Wie(hoehe)} m, gerechnet mit der Stufe {Formatting.Number(stufe.HoeheMeter, 1)} m " + + $"(Stufen {Stufen} m)."; + var basisZeile = $"Basisbreite: {Wie(hoehe)} m × {Basisfaktor} = {Formatting.Number(basis, 1)} m" + + $"{Aufgerundet(hoehe * Sandsackvorgaben.BasisbreiteJeHoehe, basis)}."; + + if (laengeMeter is not { } laenge) + { + return + [ + hoeheZeile, + $"Sandsäcke: Länge × {Wie(stufe.SaeckeJeMeter)} je m, aufgerundet.", + $"Sand: Länge × {Wie(stufe.SandKubikmeterJeMeter)} m³ je m, aufgerundet auf 0,1 m³.", + $"Sand, nass: m³ × {Nass} t/m³.", + $"Sand, trocken: {TrockenMin} bis {TrockenMax} t/m³. {WarumNass}", + $"Arbeitszeit: Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde ÷ Helfer, " + + "aufgerundet auf die Viertelstunde.", + basisZeile, + SichereSeite, + ]; + } + + var saecke = SandsackRechner.Saecke(laenge, stufe); + var sand = SandsackRechner.SandKubikmeter(laenge, stufe); + var nass = SandsackRechner.SandTonnen(sand); + var (trockenMin, trockenMax) = SandsackRechner.SandTrockenTonnen(sand); + var sandText = Formatting.Number(sand, 1); + + return + [ + hoeheZeile, + $"Sandsäcke: {Wie(laenge)} m × {Wie(stufe.SaeckeJeMeter)} je m = {Formatting.Number(saecke, 0)}" + + $"{Aufgerundet(laenge * stufe.SaeckeJeMeter, saecke)}.", + $"Sand: {Wie(laenge)} m × {Wie(stufe.SandKubikmeterJeMeter)} m³ je m = {sandText} m³" + + $"{Aufgerundet(laenge * stufe.SandKubikmeterJeMeter, sand)}.", + $"Sand, nass: {sandText} m³ × {Nass} t/m³ = {Formatting.Number(nass, 1)} t.", + $"Sand, trocken: {sandText} m³ × {TrockenMin} bis {TrockenMax} t/m³ = " + + $"{Formatting.Number(trockenMin, 1)} bis {Formatting.Number(trockenMax, 1)} t" + + $"{TrockenAufgerundet(sand, trockenMin, trockenMax)}. {WarumNass}", + Arbeitszeit(saecke, helfer), + basisZeile, + SichereSeite, + ]; + } + + /// A working time as the result shows it: "80 h", "5 h 45 min". + public static string Dauer(TimeSpan dauer) + { + var stunden = (int)dauer.TotalHours; + return dauer.Minutes == 0 + ? $"{Formatting.Number(stunden)} h" + : $"{Formatting.Number(stunden)} h {Formatting.Number(dauer.Minutes)} min"; + } + + private static string Arbeitszeit(decimal saecke, decimal? helfer) + { + var saeckeText = Formatting.Number(saecke, 0); + if (helfer is not { } anzahl) + { + return $"Arbeitszeit: {saeckeText} Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde ÷ Helfer, " + + "aufgerundet auf die Viertelstunde."; + } + + var ganze = Math.Floor(anzahl); + var zeit = SandsackRechner.Arbeitszeit(saecke, anzahl); + var viertelstunden = saecke * Sandsackvorgaben.ArbeitsgaengeJeSack * 4m + / Sandsackvorgaben.SaeckeJeHelferUndStunde / ganze; + var gerundet = viertelstunden == Math.Floor(viertelstunden) ? string.Empty : ", aufgerundet auf die Viertelstunde"; + var nurGanze = ganze == anzahl ? string.Empty : " Nur ganze Helfer zählen."; + return $"Arbeitszeit: {saeckeText} Säcke × {Arbeitsgaenge} ÷ {Leistung} je Helfer und Stunde " + + $"÷ {Formatting.Number(ganze, 0)} Helfer = {Dauer(zeit)}{gerundet}.{nurGanze}"; + } + + private static string Aufgerundet(decimal exakt, decimal gerundet) => + exakt == gerundet ? string.Empty : ", aufgerundet"; + + /// The rounding note for the dry range: it applies when either end was rounded up. + private static string TrockenAufgerundet(decimal kubikmeter, decimal min, decimal max) => + kubikmeter * Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter == min + && kubikmeter * Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter == max + ? string.Empty + : ", aufgerundet"; + + /// A number with as many decimals as it was written with: "100", "0,8", "9,6". + private static string Wie(decimal value) => Formatting.Number(value, value.Scale); + + /// + /// The figures of the table's rows, "0,5 / 1,0 / 1,5 / 2,0". No-break spaces keep the list on + /// one line, so a narrow phone never wraps it between two of its figures. + /// + private static string Liste(IEnumerable values) => string.Join(" / ", values.Select(Wie)); +} diff --git a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechner.cs b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechner.cs index 812b51d..a0d7beb 100644 --- a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechner.cs +++ b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackRechner.cs @@ -49,6 +49,24 @@ public static decimal SandKubikmeter(decimal laengeMeter, Dammstufe stufe) public static decimal SandTonnen(decimal kubikmeter) => RoundUp(kubikmeter * Sandsackvorgaben.SandTonnenJeKubikmeter, 1); + /// + /// What of dry sand weigh, from TK's lightest to its heaviest dry + /// figure, in tonnes to one decimal. Both ends round up, as the wet weight does. + /// + public static (decimal Min, decimal Max) SandTrockenTonnen(decimal kubikmeter) => + (RoundUp(kubikmeter * Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter, 1), + RoundUp(kubikmeter * Sandsackvorgaben.SandTrockenMaxTonnenJeKubikmeter, 1)); + + /// + /// How much more wet sand weighs than the lightest dry sand, in whole percent: 2,0 t against + /// 1,2 t is 67 %. + /// + public static decimal NassMehrgewichtProzent => + Math.Round( + ((Sandsackvorgaben.SandTonnenJeKubikmeter / Sandsackvorgaben.SandTrockenMinTonnenJeKubikmeter) - 1m) * 100m, + 0, + MidpointRounding.AwayFromZero); + /// /// How long take to fill, carry and lay , /// rounded up to the quarter hour. Part of a Helfer does not count: 2,5 Helfer work as 2. diff --git a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackViewModel.cs b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackViewModel.cs index ddbec7b..0286249 100644 --- a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackViewModel.cs +++ b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/SandsackViewModel.cs @@ -18,9 +18,6 @@ public sealed partial class SandsackViewModel : ObservableObject private static readonly string MaxHoeheText = Formatting.Number(SandsackRechner.MaxHoeheMeter, 1); - private static readonly string Arbeitsweise = - $"Arbeitszeit für Füllen, Tragen und Verlegen, {Formatting.Number(Sandsackvorgaben.SaeckeJeHelferUndStunde, 0)} Säcke je Helfer und Stunde."; - private readonly IHelperSettings _settings; public SandsackViewModel(IHelperSettings settings) @@ -52,6 +49,10 @@ public SandsackViewModel(IHelperSettings settings) [ObservableProperty] private string _hinweis = string.Empty; + /// How the results are calculated, one step per line, with the values entered so far (#87). + [ObservableProperty] + private IReadOnlyList _rechenweg = []; + [RelayCommand] private void Reset() { @@ -60,22 +61,15 @@ private void Reset() Helfer.Text = string.Empty; } - private static string Dauer(TimeSpan dauer) - { - var stunden = (int)dauer.TotalHours; - return dauer.Minutes == 0 - ? $"{Formatting.Number(stunden)} h" - : $"{Formatting.Number(stunden)} h {Formatting.Number(dauer.Minutes)} min"; - } - private NumberField Field(NumberFieldRule rule) => new(_settings, rule with { Key = $"{SandsackModule.HelperId}.{rule.Key}" }, Recalculate); private void Recalculate() { + Rechenweg = SandsackRechenweg.Zeilen(Laenge.Value, Hoehe.Value, Helfer.Value); if (Hoehe.Value is not { } hoehe) { - Hinweis = $"{Ratschlag} {Arbeitsweise}"; + Hinweis = Ratschlag; Results = []; return; } @@ -83,7 +77,7 @@ private void Recalculate() var stufe = SandsackRechner.Stufe(hoehe); Hinweis = $"Gerechnet für {Formatting.Number(stufe.HoeheMeter, 1)} m Höhe. " + $"Basisbreite mindestens {Formatting.Number(SandsackRechner.Basisbreite(hoehe), 1)} m. " - + $"{Ratschlag} {Arbeitsweise}"; + + Ratschlag; if (Laenge.Value is not { } laenge) { @@ -102,7 +96,7 @@ private void Recalculate() if (Helfer.Value is { } helfer) { - lines.Add(new("Arbeitszeit", Dauer(SandsackRechner.Arbeitszeit(saecke, helfer)))); + lines.Add(new("Arbeitszeit", SandsackRechenweg.Dauer(SandsackRechner.Arbeitszeit(saecke, helfer)))); } Results = lines; diff --git a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/Sandsackvorgaben.cs b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/Sandsackvorgaben.cs index 7276823..768c646 100644 --- a/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/Sandsackvorgaben.cs +++ b/src/Helpers/Sandsack/FwAssist.Helpers.Sandsack/Sandsackvorgaben.cs @@ -45,6 +45,15 @@ public static class Sandsackvorgaben /// public const decimal SandTonnenJeKubikmeter = 2m; + /// + /// TK, "Deichverteidigungsmaterialien", Sand: "Gewicht trocken 1.200 - 1.600 Kg/m³", the lower + /// end, in tonnes. Shown to explain the span only. No result is planned with it. + /// + public const decimal SandTrockenMinTonnenJeKubikmeter = 1.2m; + + /// The upper end of TK's dry weight; see . + public const decimal SandTrockenMaxTonnenJeKubikmeter = 1.6m; + /// TK, "Sandsackdamm, normale Stabilität": "b = > 2*h". public const decimal BasisbreiteJeHoehe = 2m; diff --git a/tests/FwAssist.Acceptance.Tests/DemoFlowRenderTests.cs b/tests/FwAssist.Acceptance.Tests/DemoFlowRenderTests.cs index 2f1778d..4f04fd9 100644 --- a/tests/FwAssist.Acceptance.Tests/DemoFlowRenderTests.cs +++ b/tests/FwAssist.Acceptance.Tests/DemoFlowRenderTests.cs @@ -557,17 +557,35 @@ public void The_sandsack_fields_and_reset_stay_glove_sized_on_a_320_dp_phone() } // 780 dp is about what a 915 dp phone leaves between its status and navigation bars. + // The explanation below may scroll; the fields and every result may not. [AvaloniaFact] - public void A_whole_sandsack_calculation_fits_without_scrolling() + public void A_whole_sandsack_result_fits_without_scrolling() { var phone = new PhoneRender(); phone.Window.Height = 780; FilledSandsack(phone); var form = phone.Window.GetVisualDescendants().OfType().Single(s => s.Name == "Form"); + var results = Named(phone, "ResultPanel"); + var bottom = results.TranslatePoint(new Point(0, results.Bounds.Height), form); + Assert.NotNull(bottom); Assert.True( - form.Extent.Height <= form.Viewport.Height + 1, - $"The form is {form.Extent.Height} high in a viewport of {form.Viewport.Height}"); + bottom.Value.Y <= form.Viewport.Height + 1, + $"The results end at {bottom.Value.Y} in a viewport of {form.Viewport.Height}"); + } + + [AvaloniaFact] + public void The_sandsack_explains_its_calculation_below_the_result() + { + var phone = new PhoneRender(); + var page = FilledSandsack(phone); + + var lines = Named(phone, "Rechenweg").GetVisualDescendants().OfType() + .Where(t => t.IsEffectivelyVisible) + .Select(t => t.Text ?? string.Empty) + .ToList(); + Assert.Equal(page.Rechenweg, lines); + Assert.Contains(lines, l => l.StartsWith("Sand, trocken: 300,0 m³ × 1,2 bis 1,6 t/m³ = 360,0 bis 480,0 t.", StringComparison.Ordinal)); } private static Control Named(PhoneRender phone, string name) => diff --git a/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechenwegTests.cs b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechenwegTests.cs new file mode 100644 index 0000000..65cce0a --- /dev/null +++ b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechenwegTests.cs @@ -0,0 +1,121 @@ +namespace FwAssist.Helpers.Sandsack.Tests; + +public class SandsackRechenwegTests +{ + [Fact] + public void Without_values_every_step_names_its_rule_and_the_tables_figures() + { + var zeilen = Zeilen(null, null, null); + + Assert.Equal( + [ + "Höhe: aufgerundet auf die nächste Stufe der Tabelle, 0,5 / 1,0 / 1,5 / 2,0 m.", + "Sandsäcke: Länge × Säcke je m der Stufe (45 / 160 / 350 / 580), aufgerundet.", + "Sand: Länge × m³ je m der Stufe (1 / 3 / 6 / 9,6), aufgerundet auf 0,1 m³.", + "Sand, nass: m³ × 2,0 t/m³.", + "Sand, trocken: 1,2 bis 1,6 t/m³. Nasser Sand wiegt bis zu 67 % mehr als trockener. " + + "Gerechnet wird mit nassem Sand, damit Ladung und Fahrten reichen.", + "Arbeitszeit: Säcke × 2 Arbeitsgänge (Füllen und Tragen, Verlegen) ÷ 40 Säcke je Helfer und Stunde " + + "÷ Helfer, aufgerundet auf die Viertelstunde. Nur ganze Helfer zählen.", + "Basisbreite: Höhe × 2.", + SandsackRechenweg.SichereSeite, + ], + Zeilen(null, null, null)); + Assert.Equal(zeilen, Zeilen(100m, null, 10m)); + } + + [Fact] + public void A_whole_calculation_shows_the_numbers_it_used() + { + Assert.Equal( + [ + "Höhe: 1 m, gerechnet mit der Stufe 1,0 m (Stufen 0,5 / 1,0 / 1,5 / 2,0 m).", + "Sandsäcke: 100 m × 160 je m = 16.000.", + "Sand: 100 m × 3 m³ je m = 300,0 m³.", + "Sand, nass: 300,0 m³ × 2,0 t/m³ = 600,0 t.", + "Sand, trocken: 300,0 m³ × 1,2 bis 1,6 t/m³ = 360,0 bis 480,0 t. " + + "Nasser Sand wiegt bis zu 67 % mehr als trockener. " + + "Gerechnet wird mit nassem Sand, damit Ladung und Fahrten reichen.", + "Arbeitszeit: 16.000 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ 10 Helfer = 80 h.", + "Basisbreite: 1 m × 2 = 2,0 m.", + SandsackRechenweg.SichereSeite, + ], + Zeilen(100m, 1m, 10m)); + } + + [Fact] + public void A_height_alone_shows_its_row_and_base_and_the_rules_for_the_rest() + { + var zeilen = Zeilen(null, 0.8m, null); + + Assert.Equal("Höhe: 0,8 m, gerechnet mit der Stufe 1,0 m (Stufen 0,5 / 1,0 / 1,5 / 2,0 m).", zeilen[0]); + Assert.Equal("Sandsäcke: Länge × 160 je m, aufgerundet.", zeilen[1]); + Assert.Equal("Basisbreite: 0,8 m × 2 = 1,6 m.", zeilen[6]); + } + + [Fact] + public void A_step_that_was_rounded_says_so() + { + // 10,5 m × 45 = 472,5 sacks; 10,5 m × 1 m³ = 10,5 m³; 473 × 2 ÷ 40 ÷ 4 = 5,9125 h. + var zeilen = Zeilen(10.5m, 0.5m, 4m); + + Assert.Equal("Sandsäcke: 10,5 m × 45 je m = 473, aufgerundet.", zeilen[1]); + Assert.Equal("Sand: 10,5 m × 1 m³ je m = 10,5 m³.", zeilen[2]); + Assert.Equal( + "Arbeitszeit: 473 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ 4 Helfer = 6 h, aufgerundet auf die Viertelstunde.", + zeilen[5]); + } + + // 23 m × 160 = 3.680 sacks; × 2 ÷ 40 ÷ 32 = 5,75 h, an exact quarter hour, so nothing rounds. + [Fact] + public void A_time_that_ends_on_a_quarter_hour_is_not_called_rounded() => + Assert.Equal( + "Arbeitszeit: 3.680 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ 32 Helfer = 5 h 45 min.", + Zeilen(23m, 1m, 32m)[5]); + + // 450 × 2 ÷ 40 ÷ 4 = 5,625 h: rounded up to 5 h 45 min. + [Fact] + public void A_time_between_quarter_hours_is_called_rounded() => + Assert.Equal( + "Arbeitszeit: 450 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ 4 Helfer = 5 h 45 min, aufgerundet auf die Viertelstunde.", + Zeilen(10m, 0.5m, 4m)[5]); + + // 1,01 m × 3 m³ = 3,03, so 3,1 m³; × 1,2 and × 1,6 are 3,72 and 4,96 t. + [Fact] + public void A_dry_range_that_was_rounded_says_so() => + Assert.StartsWith( + "Sand, trocken: 3,1 m³ × 1,2 bis 1,6 t/m³ = 3,8 bis 5,0 t, aufgerundet. ", + Zeilen(1.01m, 1m, null)[4], + StringComparison.Ordinal); + + [Fact] + public void A_base_that_was_rounded_says_so() => + Assert.Equal("Basisbreite: 0,77 m × 2 = 1,6 m, aufgerundet.", Zeilen(null, 0.77m, null)[6]); + + [Fact] + public void Part_of_a_helfer_is_dropped_and_the_line_says_why() => + Assert.Equal( + "Arbeitszeit: 16.000 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ 10 Helfer = 80 h. Nur ganze Helfer zählen.", + Zeilen(100m, 1m, 10.5m)[5]); + + [Fact] + public void Without_helfer_the_time_shows_the_sacks_and_the_rule() => + Assert.Equal( + "Arbeitszeit: 16.000 Säcke × 2 ÷ 40 je Helfer und Stunde ÷ Helfer, aufgerundet auf die Viertelstunde.", + Zeilen(100m, 1m, null)[5]); + + [Fact] + public void The_list_of_rows_never_wraps_between_two_figures() => + Assert.Contains( + "0,5 / 1,0 / 1,5 / 2,0 m", + SandsackRechenweg.Zeilen(null, null, null)[0], + StringComparison.Ordinal); + + [Fact] + public void A_result_line_and_its_explanation_agree() => + Assert.Equal("5 h 45 min", SandsackRechenweg.Dauer(SandsackRechner.Arbeitszeit(450m, 4m))); + + // The lists are joined with no-break spaces; the expectations above are written with plain ones. + private static string[] Zeilen(decimal? laengeMeter, decimal? hoeheMeter, decimal? helfer) => + [.. SandsackRechenweg.Zeilen(laengeMeter, hoeheMeter, helfer).Select(z => z.Replace(' ', ' '))]; +} diff --git a/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechnerTests.cs b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechnerTests.cs index a03a565..2c798a2 100644 --- a/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechnerTests.cs +++ b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackRechnerTests.cs @@ -66,6 +66,18 @@ public void A_tiny_real_part_of_a_quarter_hour_still_counts() => public void An_amount_just_below_a_whole_tenth_is_not_rounded_past_it() => Assert.Equal(1m, SandsackRechner.SandKubikmeter(1m / 3m * 3m, SandsackRechner.Stufe(0.5m))); + [Fact] + public void Dry_sand_weighs_one_point_two_to_one_point_six_tonnes_a_cubic_metre() => + Assert.Equal((360m, 480m), SandsackRechner.SandTrockenTonnen(300m)); + + [Fact] + public void Both_ends_of_the_dry_weight_round_up_to_a_tenth() => + Assert.Equal((3.8m, 5m), SandsackRechner.SandTrockenTonnen(3.1m)); + + [Fact] + public void Wet_sand_weighs_two_thirds_more_than_the_lightest_dry_sand() => + Assert.Equal(67m, SandsackRechner.NassMehrgewichtProzent); + [Fact] public void Wet_sand_weighs_two_tonnes_a_cubic_metre() => Assert.Equal(6.2m, SandsackRechner.SandTonnen(3.1m)); diff --git a/tests/FwAssist.Helpers.Sandsack.Tests/SandsackViewModelTests.cs b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackViewModelTests.cs index 72b0e38..f8914d2 100644 --- a/tests/FwAssist.Helpers.Sandsack.Tests/SandsackViewModelTests.cs +++ b/tests/FwAssist.Helpers.Sandsack.Tests/SandsackViewModelTests.cs @@ -86,7 +86,38 @@ public void Without_a_height_the_hint_still_says_how_to_build() var vm = Page(); Assert.StartsWith("Dichter Verbund", vm.Hinweis, StringComparison.Ordinal); - Assert.Contains("40 Säcke je Helfer und Stunde", vm.Hinweis, StringComparison.Ordinal); + } + + [Fact] + public void A_new_page_explains_the_rules_before_anything_is_entered() + { + var vm = Page(); + + Assert.Equal(SandsackRechenweg.Zeilen(null, null, null), vm.Rechenweg); + Assert.Contains(vm.Rechenweg, z => z.Contains("40 Säcke je Helfer und Stunde", StringComparison.Ordinal)); + } + + [Fact] + public void The_explanation_follows_what_is_typed() + { + var vm = Page(); + + vm.Laenge.Text = "100"; + vm.Hoehe.Text = "1"; + vm.Helfer.Text = "10"; + + Assert.Equal(SandsackRechenweg.Zeilen(100m, 1m, 10m), vm.Rechenweg); + Assert.Contains("Sandsäcke: 100 m × 160 je m = 16.000.", vm.Rechenweg); + } + + [Fact] + public void The_rate_of_work_is_explained_once_not_also_in_the_hint() + { + var vm = Page(); + + vm.Hoehe.Text = "1"; + + Assert.DoesNotContain("je Helfer und Stunde", vm.Hinweis, StringComparison.Ordinal); } [Fact]