using Schaad.OpenData.Watercraft.Analysis; using Schaad.OpenData.Watercraft.Storage; using static Schaad.OpenData.Tests.WatercraftTestData; namespace Schaad.OpenData.Tests; public class WatercraftAnalysisTestShould { [Fact] public void OrderCategoriesByFrequencyAcrossAllYearsWhenBuildingDimensions() { var snapshot = new WatercraftSnapshot( [ Year(2023, Vessel(type: "Ruderboot")), Year(2024, Vessel(type: "Motorschiff"), Vessel(type: "Motorschiff"), Vessel(type: "Ruderboot"), Vessel(type: "Pedalo")), ], null); var type = WatercraftAnalysis.BuildDimensions(snapshot).Single(d => d.Key == "type"); type.Categories.ShouldBe(["Motorschiff", "Ruderboot", "Pedalo"]); } [Fact] public void LabelMissingFuelAsNoEngineWhenVesselHasNoMotor() { var snapshot = new WatercraftSnapshot([Year(2023, Vessel(fuel: null, powerKw: null), Vessel(fuel: "Benzin"))], null); var dimensions = WatercraftAnalysis.BuildDimensions(snapshot); dimensions.Single(d => d.Key == "fuel").Categories.ShouldBe(["Benzin", "Ohne Motor"]); dimensions.Single(d => d.Key == "emission").Categories.ShouldBe(["Keine Angabe", "Ohne Motor"]); dimensions.Single(d => d.Key == "use").Categories.ShouldBe(["Ohne besondere Verwendung"]); } [Fact] public void CountVesselsPerLocationAndCategoryWhenBuildingYear() { var snapshot = new WatercraftSnapshot( [Year(2023, Vessel("Arbon"), Vessel("Arbon", type: "Ruderboot"), Vessel("Horn"))], null); var year = WatercraftAnalysis.BuildYears(snapshot).ShouldHaveSingleItem(); year.Canton.Count.ShouldBe(3); year.Canton.Categories["type"].ShouldBe([2, 1]); var arbon = year.Locations[0]; arbon.Name.ShouldBe("Arbon"); arbon.Count.ShouldBe(2); arbon.Categories["type"].ShouldBe([1, 1]); arbon.Lat.ShouldNotBeNull(); year.Locations[1].Categories["type"].ShouldBe([1, 0]); } [Fact] public void LeavePositionEmptyWhenLocationIsUnknown() { var snapshot = new WatercraftSnapshot([Year(2023, Vessel("ohne festen Standort"))], null); var location = WatercraftAnalysis.BuildYears(snapshot).Single().Locations.ShouldHaveSingleItem(); location.Lat.ShouldBeNull(); location.Lon.ShouldBeNull(); } [Fact] public void SortLengthAndPowerIntoBinsWhenSummarizing() { var snapshot = new WatercraftSnapshot( [ Year( 2023, Vessel(lengthCm: 350, powerKw: null, fuel: null), Vessel(lengthCm: 600, powerKw: 6), Vessel(lengthCm: 1250, powerKw: 400), Vessel(lengthCm: null, powerKw: 30)), ], null); var canton = WatercraftAnalysis.BuildYears(snapshot).Single().Canton; canton.LengthBins.ShouldBe([1, 0, 1, 0, 0, 1]); canton.PowerBins.ShouldBe([1, 1, 0, 1, 0, 0, 1]); canton.MedianLengthM.ShouldBe(6); canton.MedianPowerKw.ShouldBe(30); } [Fact] public void RequireLicenseWhenPowerOrSailAreaExceedsLimit() { WatercraftAnalysis.RequiresLicense(Vessel(powerKw: 6, sailAreaM2: 15)).ShouldBeFalse(); WatercraftAnalysis.RequiresLicense(Vessel(powerKw: 6.1)).ShouldBeTrue(); WatercraftAnalysis.RequiresLicense(Vessel(powerKw: null, sailAreaM2: 22)).ShouldBeTrue(); } [Fact] public void ListYearsWithCountsWhenBuildingOverview() { var snapshot = new WatercraftSnapshot([Year(2024, Vessel()), Year(2023, Vessel(), Vessel())], null); var overview = WatercraftAnalysis.BuildOverview(snapshot); overview.Years.Select(y => (y.Year, y.Count)).ShouldBe([(2023, 2), (2024, 1)]); overview.PowerBins.Count.ShouldBe(7); } }