Esempio n. 1
0
        public void GetUniqueDisplayNameForCalculations_ValidParameters_ReturnsExpectedDisplayName()
        {
            // Setup
            var calculation     = new object();
            var allCalculations = new ObservableList <object>();
            int randomNumberOfCalculationElements = new Random().Next() % 10;

            for (var i = 0; i < randomNumberOfCalculationElements; i++)
            {
                allCalculations.Add(new object());
            }

            allCalculations.Add(calculation);

            // Call
            string name = TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(calculation, allCalculations, o => 0.01);

            // Assert
            var expectedName = "1/100";

            if (randomNumberOfCalculationElements != 0)
            {
                expectedName += $" ({randomNumberOfCalculationElements})";
            }

            Assert.AreEqual(expectedName, name);
        }
 private IReadOnlyDictionary <IObservableEnumerable <HydraulicBoundaryLocationCalculation>, string> GetWaveHeightCalculations()
 {
     return(assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities
            .OrderByDescending(tp => tp.TargetProbability)
            .ToDictionary(x => (IObservableEnumerable <HydraulicBoundaryLocationCalculation>)x.HydraulicBoundaryLocationCalculations,
                          x => string.Format(Resources.MetaData_WaveHeight_TargetProbability_0,
                                             TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(x,
                                                                                                                                assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
                                                                                                                                y => y.TargetProbability))));
 }
Esempio n. 3
0
        public void GetUniqueDisplayNameForCalculations_CalculationsNotInEnumerationOfAllCalculations_ThrowsInvalidOperationException()
        {
            // Call
            void Call() => TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(
                new object(), Enumerable.Empty <object>(), o => double.NaN);

            // Assert
            var exception = Assert.Throws <InvalidOperationException>(Call);

            Assert.AreEqual("The provided calculations object is not part of the enumeration that contains all calculations.", exception.Message);
        }
Esempio n. 4
0
        public void GetUniqueDisplayNameForCalculations_GetTargetProbabilityFuncNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(
                new object(), Enumerable.Empty <object>(), null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("getTargetProbabilityFunc", exception.ParamName);
        }
Esempio n. 5
0
        public void GetUniqueDisplayNameForCalculations_AllCalculationsNull_ThrowsArgumentNullException()
        {
            // Call
            void Call() => TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(
                new object(), null, calculation => double.NaN);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("allCalculations", exception.ParamName);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a collection of <see cref="CalculatableActivity"/> for all user defined target probability based wave height calculations
        /// within the given <see cref="IAssessmentSection"/>.
        /// </summary>
        /// <param name="assessmentSection">The assessment section to create the activities for.</param>
        /// <returns>A collection of <see cref="CalculatableActivity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="assessmentSection"/> is <c>null</c>.</exception>
        public static IEnumerable <CalculatableActivity> CreateWaveHeightCalculationActivitiesForUserDefinedTargetProbabilities(IAssessmentSection assessmentSection)
        {
            if (assessmentSection == null)
            {
                throw new ArgumentNullException(nameof(assessmentSection));
            }

            return(assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities
                   .SelectMany(whc => HydraulicBoundaryLocationCalculationActivityFactory.CreateWaveHeightCalculationActivities(
                                   whc.HydraulicBoundaryLocationCalculations,
                                   assessmentSection,
                                   whc.TargetProbability,
                                   TargetProbabilityCalculationsDisplayNameHelper.GetUniqueDisplayNameForCalculations(whc,
                                                                                                                      assessmentSection.WaveHeightCalculationsForUserDefinedTargetProbabilities,
                                                                                                                      c => c.TargetProbability)))
                   .ToList());
        }