public void CreateHydraulicBoundaryLocationFeature_WithLocation_ReturnFeature() { // Setup var random = new Random(39); IEnumerable <Tuple <string, RoundedDouble> > waterLevelCalculationForTargetProbabilities = new[] { new Tuple <string, RoundedDouble>("h - 1/10", random.NextRoundedDouble()), new Tuple <string, RoundedDouble>("h - 1/10 (1)", random.NextRoundedDouble()) }; IEnumerable <Tuple <string, RoundedDouble> > waveHeightCalculationForTargetProbabilities = new[] { new Tuple <string, RoundedDouble>("Hs - 1/1.000", random.NextRoundedDouble()) }; var location = new AggregatedHydraulicBoundaryLocation(1, "test", new Point2D(0, 0), waterLevelCalculationForTargetProbabilities, waveHeightCalculationForTargetProbabilities); // Call MapFeature feature = HydraulicBoundaryLocationMapDataFeaturesFactory.CreateHydraulicBoundaryLocationFeature(location); // Assert MapFeaturesMetaDataTestHelper.AssertMetaData(location.Id, feature, "ID"); MapFeaturesMetaDataTestHelper.AssertMetaData(location.Name, feature, "Naam"); MapFeaturesMetaDataTestHelper.AssertMetaData(location.WaterLevelCalculationsForTargetProbabilities.First().Item2.ToString(), feature, "h - 1/10"); MapFeaturesMetaDataTestHelper.AssertMetaData(location.WaterLevelCalculationsForTargetProbabilities.Last().Item2.ToString(), feature, "h - 1/10 (1)"); MapFeaturesMetaDataTestHelper.AssertMetaData(location.WaveHeightCalculationsForTargetProbabilities.First().Item2.ToString(), feature, "Hs - 1/1.000"); }
private static void AssertMetaData(IEnumerable <HydraulicBoundaryLocationCalculation> calculations, HydraulicBoundaryLocation hydraulicBoundaryLocation, MapFeature mapFeature, double targetProbability, string displayName, List <string> presentedMetaDataItems) { string uniqueName = NamingHelper.GetUniqueName( presentedMetaDataItems, string.Format(displayName, ProbabilityFormattingHelper.Format(targetProbability)), v => v); MapFeaturesMetaDataTestHelper.AssertMetaData( GetExpectedResult(calculations, hydraulicBoundaryLocation), mapFeature, uniqueName); presentedMetaDataItems.Add(uniqueName); }
public void CreateHydraulicBoundaryLocationCalculationFeature_WithData_ReturnFeature(bool calculationHasOutput) { // Setup const string metaDataHeader = "header"; var calculation = new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation("location 1")); if (calculationHasOutput) { calculation.Output = new TestHydraulicBoundaryLocationCalculationOutput(); } // Call MapFeature feature = HydraulicBoundaryLocationMapDataFeaturesFactory.CreateHydraulicBoundaryLocationCalculationFeature( calculation, metaDataHeader); // Assert RoundedDouble expectedMetaDataValue = calculationHasOutput ? calculation.Output.Result : RoundedDouble.NaN; MapFeaturesMetaDataTestHelper.AssertMetaData(expectedMetaDataValue.ToString(), feature, metaDataHeader); }
public void AddTargetProbabilityMetaData_WithAllData_AddsMetaDataItems() { // Setup const string displayNameFormat = "Test - {0}"; var random = new Random(21); var feature = new MapFeature(Enumerable.Empty <MapGeometry>()); var targetProbabilities = new[] { new Tuple <double, RoundedDouble>(0.01, random.NextRoundedDouble()), new Tuple <double, RoundedDouble>(0.01, RoundedDouble.NaN), new Tuple <double, RoundedDouble>(0.0001, random.NextRoundedDouble()) }; // Call HydraulicBoundaryLocationMapDataFeaturesFactory.AddTargetProbabilityMetaData(feature, targetProbabilities, displayNameFormat); // Assert Assert.AreEqual(3, feature.MetaData.Count); MapFeaturesMetaDataTestHelper.AssertMetaData(targetProbabilities[0].Item2.ToString(), feature, string.Format(displayNameFormat, "1/100")); MapFeaturesMetaDataTestHelper.AssertMetaData(targetProbabilities[1].Item2.ToString(), feature, string.Format(displayNameFormat, "1/100 (1)")); MapFeaturesMetaDataTestHelper.AssertMetaData(targetProbabilities[2].Item2.ToString(), feature, string.Format(displayNameFormat, "1/10.000")); }
/// <summary> /// Asserts whether <paramref name="features"/> contains the data that is representative for the data of /// hydraulic boundary locations and calculations in <paramref name="assessmentSection"/>. /// </summary> /// <param name="assessmentSection">The assessment section that contains the original data.</param> /// <param name="features">The features that need to be asserted.</param> /// <exception cref="AssertionException">Thrown when: /// <list type="bullet"> /// <item>the number of hydraulic boundary locations and features are not the same;</item> /// <item>the general properties (such as id, name and location) of hydraulic boundary locations and features /// are not the same;</item> /// <item>the wave height or the design water level calculation results of a hydraulic boundary location and the /// respective outputs of a corresponding feature are not the same.</item> /// </list> /// </exception> public static void AssertHydraulicBoundaryFeaturesData(IAssessmentSection assessmentSection, IEnumerable <MapFeature> features) { HydraulicBoundaryLocation[] hydraulicBoundaryLocationsArray = assessmentSection.HydraulicBoundaryDatabase.Locations.ToArray(); int expectedNrOfFeatures = hydraulicBoundaryLocationsArray.Length; Assert.AreEqual(expectedNrOfFeatures, features.Count()); for (var i = 0; i < expectedNrOfFeatures; i++) { HydraulicBoundaryLocation hydraulicBoundaryLocation = hydraulicBoundaryLocationsArray[i]; MapFeature mapFeature = features.ElementAt(i); Assert.AreEqual(hydraulicBoundaryLocation.Location, mapFeature.MapGeometries.First().PointCollections.First().First()); MapFeaturesMetaDataTestHelper.AssertMetaData(hydraulicBoundaryLocation.Id, mapFeature, "ID"); MapFeaturesMetaDataTestHelper.AssertMetaData(hydraulicBoundaryLocation.Name, mapFeature, "Naam"); var presentedMetaDataItems = new List <string>(); AssertMetaData(assessmentSection.WaterLevelCalculationsForMaximumAllowableFloodingProbability, hydraulicBoundaryLocation, mapFeature, assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability, "h - {0}", presentedMetaDataItems); AssertMetaData(assessmentSection.WaterLevelCalculationsForSignalFloodingProbability, hydraulicBoundaryLocation, mapFeature, assessmentSection.FailureMechanismContribution.SignalFloodingProbability, "h - {0}", presentedMetaDataItems); foreach (HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability in assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities) { AssertMetaData(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations, hydraulicBoundaryLocation, mapFeature, calculationsForTargetProbability.TargetProbability, "h - {0}", presentedMetaDataItems); } foreach (HydraulicBoundaryLocationCalculationsForTargetProbability calculationsForTargetProbability in assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities) { AssertMetaData(calculationsForTargetProbability.HydraulicBoundaryLocationCalculations, hydraulicBoundaryLocation, mapFeature, calculationsForTargetProbability.TargetProbability, "Hs - {0}", presentedMetaDataItems); } } }
/// <summary> /// Asserts whether <paramref name="features"/> contains the data that is representative for the data of /// dune locations and calculations in <paramref name="failureMechanism"/>. /// </summary> /// <param name="failureMechanism">The failure mechanism that contains the first part of the original data.</param> /// <param name="features">The collection of <see cref="MapFeature"/> to assert.</param> /// <exception cref="AssertionException">Thrown when: /// <list type="bullet"> /// <item>the number of dune locations and features are not the same;</item> /// <item>the general properties (such as id, name and location) of dune locations and features /// are not the same;</item> /// <item>the water level, wave height or wave period calculation results of a dune location and the /// respective outputs of a corresponding feature are not the same.</item> /// <item>the number of meta data items does not match with the expected number of items.</item> /// </list> /// </exception> public static void AssertDuneLocationFeaturesData(DuneErosionFailureMechanism failureMechanism, IEnumerable <MapFeature> features) { IEnumerable <DuneLocation> expectedDuneLocations = failureMechanism.DuneLocations; Assert.AreEqual(expectedDuneLocations.Count(), features.Count()); for (var i = 0; i < expectedDuneLocations.Count(); i++) { DuneLocation expectedDuneLocation = expectedDuneLocations.ElementAt(i); MapFeature mapFeature = features.ElementAt(i); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Id, mapFeature, "ID"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Name, mapFeature, "Naam"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.CoastalAreaId, mapFeature, "Kustvaknummer"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Offset.ToString("0.#", CultureInfo.CurrentCulture), mapFeature, "Metrering"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.D50.ToString(), mapFeature, "Rekenwaarde d50"); Assert.AreEqual(expectedDuneLocation.Location, mapFeature.MapGeometries.First().PointCollections.First().Single()); var presentedMetaDataItems = new List <string>(); foreach (DuneLocationCalculationsForTargetProbability calculationsForTargetProbability in failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities) { AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWaterLevel, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde h - {0}", presentedMetaDataItems); AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWaveHeight, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde Hs - {0}", presentedMetaDataItems); AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWavePeriod, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde Tp - {0}", presentedMetaDataItems); } int expectedMetaDataCount = 5 + (3 * failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Count); Assert.AreEqual(expectedMetaDataCount, mapFeature.MetaData.Keys.Count); } }