Ejemplo n.º 1
0
        public void Read_NaNParameters_ReturnsHydraulicBoundaryLocationCalculationOutputWithNaN()
        {
            // Setup
            var random      = new Random(21);
            var convergence = random.NextEnumValue <CalculationConvergence>();

            var entity = new HydraulicLocationOutputEntity
            {
                Result                 = double.NaN,
                TargetProbability      = double.NaN,
                TargetReliability      = double.NaN,
                CalculatedProbability  = double.NaN,
                CalculatedReliability  = double.NaN,
                CalculationConvergence = Convert.ToByte(convergence)
            };

            // Call
            HydraulicBoundaryLocationCalculationOutput output = entity.Read();

            // Assert
            Assert.IsNaN(output.Result);
            Assert.IsNaN(output.TargetProbability);
            Assert.IsNaN(output.TargetReliability);
            Assert.IsNaN(output.CalculatedProbability);
            Assert.IsNaN(output.CalculatedReliability);
            Assert.AreEqual(convergence, output.CalculationConvergence);
            Assert.IsNull(output.GeneralResult);
        }
Ejemplo n.º 2
0
        public void Read_ValidParameters_ReturnsHydraulicBoundaryLocationCalculationOutput()
        {
            // Setup
            var    random                = new Random(22);
            double result                = random.NextDouble();
            double targetProbability     = random.NextDouble();
            double targetReliability     = random.NextDouble();
            double calculatedProbability = random.NextDouble();
            double calculatedReliability = random.NextDouble();
            var    convergence           = random.NextEnumValue <CalculationConvergence>();
            var    entity                = new HydraulicLocationOutputEntity
            {
                Result                 = result,
                TargetProbability      = targetProbability,
                TargetReliability      = targetReliability,
                CalculatedProbability  = calculatedProbability,
                CalculatedReliability  = calculatedReliability,
                CalculationConvergence = Convert.ToByte(convergence)
            };

            // Call
            HydraulicBoundaryLocationCalculationOutput output = entity.Read();

            // Assert
            Assert.AreEqual(result, output.Result, output.Result.GetAccuracy());
            Assert.AreEqual(targetProbability, output.TargetProbability);
            Assert.AreEqual(targetReliability, output.TargetReliability, output.TargetReliability.GetAccuracy());
            Assert.AreEqual(calculatedProbability, output.CalculatedProbability);
            Assert.AreEqual(calculatedReliability, output.CalculatedReliability, output.CalculatedReliability.GetAccuracy());
            Assert.AreEqual(convergence, output.CalculationConvergence);
            Assert.IsNull(output.GeneralResult);
        }
Ejemplo n.º 3
0
        public void CreateHydraulicLocationOutputEntity_WithGeneralResult_ReturnsHydraulicLocationEntityWithGeneralResult()
        {
            // Setup
            var random = new Random(21);
            var output = new HydraulicBoundaryLocationCalculationOutput(double.NaN, double.NaN, double.NaN,
                                                                        double.NaN, double.NaN, random.NextEnumValue <CalculationConvergence>(),
                                                                        GetGeneralResult());

            // Call
            HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity();

            // Assert
            GeneralResultEntityTestHelper.AssertGeneralResultPropertyValues(output.GeneralResult, entity.GeneralResultSubMechanismIllustrationPointEntity);
        }
Ejemplo n.º 4
0
        private static HydraulicLocationOutputEntity CreateHydraulicOutputEntity(int seed)
        {
            var random = new Random(seed);
            var hydraulicLocationOutputEntity = new HydraulicLocationOutputEntity
            {
                Result                 = random.NextDouble(),
                TargetProbability      = random.NextDouble(),
                TargetReliability      = random.NextDouble(),
                CalculatedProbability  = random.NextDouble(),
                CalculatedReliability  = random.NextDouble(),
                CalculationConvergence = Convert.ToByte(CalculationConvergence.NotCalculated)
            };

            return(hydraulicLocationOutputEntity);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Read the <see cref="HydraulicLocationOutputEntity"/> and use the information to construct a <see cref="HydraulicBoundaryLocationCalculationOutput"/>.
        /// </summary>
        /// <param name="entity">The <see cref="HydraulicLocationOutputEntity"/> to create <see cref="HydraulicBoundaryLocationCalculationOutput"/> for.</param>
        /// <returns>A new <see cref="HydraulicBoundaryLocationCalculationOutput"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/> is <c>null</c>.</exception>
        internal static HydraulicBoundaryLocationCalculationOutput Read(this HydraulicLocationOutputEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(new HydraulicBoundaryLocationCalculationOutput(entity.Result.ToNullAsNaN(),
                                                                  entity.TargetProbability.ToNullAsNaN(),
                                                                  entity.TargetReliability.ToNullAsNaN(),
                                                                  entity.CalculatedProbability.ToNullAsNaN(),
                                                                  entity.CalculatedReliability.ToNullAsNaN(),
                                                                  (CalculationConvergence)entity.CalculationConvergence,
                                                                  entity.GeneralResultSubMechanismIllustrationPointEntity?.Read()));
        }
Ejemplo n.º 6
0
        private static HydraulicLocationCalculationEntity CreateCalculationEntityWithOutputAndGeneralResultEntity(int seed)
        {
            var random = new Random(seed);
            var generalResultEntity = new GeneralResultSubMechanismIllustrationPointEntity
            {
                GoverningWindDirectionName  = "A wind direction",
                GoverningWindDirectionAngle = random.NextDouble()
            };

            HydraulicLocationOutputEntity hydraulicLocationOutputEntity = CreateHydraulicOutputEntity(seed);

            hydraulicLocationOutputEntity.GeneralResultSubMechanismIllustrationPointEntity = generalResultEntity;

            HydraulicLocationCalculationEntity calculationEntity = CreateCalculationEntity(seed);

            calculationEntity.HydraulicLocationOutputEntities.Add(hydraulicLocationOutputEntity);

            return(calculationEntity);
        }
        public void Create_CalculationWithOutput_ReturnsHydraulicLocationCalculationEntityWithOutput()
        {
            // Setup
            var  random = new Random(33);
            bool shouldIllustrationPointsBeCalculated = random.NextBoolean();

            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var calculation = new HydraulicBoundaryLocationCalculation(hydraulicBoundaryLocation)
            {
                InputParameters =
                {
                    ShouldIllustrationPointsBeCalculated = shouldIllustrationPointsBeCalculated
                },
                Output = new HydraulicBoundaryLocationCalculationOutput(
                    random.NextDouble(), random.NextDouble(), random.NextDouble(), random.NextDouble(),
                    random.NextDouble(), random.NextEnumValue <CalculationConvergence>(),
                    null)
            };

            var registry = new PersistenceRegistry();
            var hydraulicLocationEntity = new HydraulicLocationEntity();

            registry.Register(hydraulicLocationEntity, hydraulicBoundaryLocation);

            // Call
            HydraulicLocationCalculationEntity entity = calculation.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(Convert.ToByte(shouldIllustrationPointsBeCalculated), entity.ShouldIllustrationPointsBeCalculated);

            HydraulicLocationOutputEntity outputEntity = entity.HydraulicLocationOutputEntities.Single();

            HydraulicBoundaryLocationCalculationOutput expectedOutput = calculation.Output;

            Assert.AreEqual(expectedOutput.CalculatedProbability, outputEntity.CalculatedProbability);
            Assert.AreEqual(expectedOutput.CalculatedReliability, outputEntity.CalculatedReliability);
            Assert.AreEqual(expectedOutput.TargetReliability, outputEntity.TargetReliability);
            Assert.AreEqual(expectedOutput.TargetProbability, outputEntity.TargetProbability);
            Assert.IsNull(outputEntity.GeneralResultSubMechanismIllustrationPointEntity);
            Assert.AreEqual(Convert.ToByte(expectedOutput.CalculationConvergence), outputEntity.CalculationConvergence);
        }
        /// <summary>
        /// Reads the <see cref="HydraulicLocationCalculationEntity"/> and uses the information to update a
        /// <see cref="HydraulicBoundaryLocationCalculation"/>.
        /// </summary>
        /// <param name="entity">The <see cref="HydraulicLocationCalculationEntity"/> to update the
        /// <see cref="HydraulicBoundaryLocationCalculation"/>.</param>
        /// <param name="calculation">The target of the read operation.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        internal static void Read(this HydraulicLocationCalculationEntity entity,
                                  HydraulicBoundaryLocationCalculation calculation)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

            calculation.InputParameters.ShouldIllustrationPointsBeCalculated = Convert.ToBoolean(entity.ShouldIllustrationPointsBeCalculated);
            HydraulicLocationOutputEntity outputEntity = entity.HydraulicLocationOutputEntities.SingleOrDefault();

            if (outputEntity != null)
            {
                calculation.Output = outputEntity.Read();
            }
        }
Ejemplo n.º 9
0
        public void CreateHydraulicLocationOutputEntity_WithNaNParameters_ReturnsHydraulicLocationEntityWithOutputNaN()
        {
            // Setup
            var random = new Random(21);
            var output = new HydraulicBoundaryLocationCalculationOutput(double.NaN, double.NaN, double.NaN,
                                                                        double.NaN, double.NaN, random.NextEnumValue <CalculationConvergence>(), null);

            // Call
            HydraulicLocationOutputEntity entity = output.CreateHydraulicLocationOutputEntity();

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNull(entity.Result);
            Assert.IsNull(entity.TargetProbability);
            Assert.IsNull(entity.TargetReliability);
            Assert.IsNull(entity.CalculatedProbability);
            Assert.IsNull(entity.CalculatedReliability);
            Assert.AreEqual((byte)output.CalculationConvergence, entity.CalculationConvergence);

            Assert.IsNull(entity.GeneralResultSubMechanismIllustrationPointEntity);
        }
Ejemplo n.º 10
0
        private static void AssertHydraulicBoundaryLocationCalculationOutput(HydraulicLocationOutputEntity expected, HydraulicBoundaryLocationCalculationOutput actual)
        {
            if (expected == null)
            {
                Assert.IsNull(actual);
                return;
            }

            Assert.IsNotNull(expected.Result);
            Assert.AreEqual((RoundedDouble)expected.Result, actual.Result, actual.Result.GetAccuracy());
            Assert.IsNotNull(expected.TargetReliability);
            Assert.AreEqual((RoundedDouble)expected.TargetReliability, actual.TargetReliability, actual.TargetReliability.GetAccuracy());
            Assert.IsNotNull(expected.TargetProbability);
            Assert.AreEqual(expected.TargetProbability, actual.TargetProbability);
            Assert.IsNotNull(expected.CalculatedReliability);
            Assert.AreEqual((RoundedDouble)expected.CalculatedReliability, actual.CalculatedReliability, actual.CalculatedReliability.GetAccuracy());
            Assert.IsNotNull(expected.CalculatedProbability);
            Assert.AreEqual(expected.CalculatedProbability, actual.CalculatedProbability);
            Assert.AreEqual((CalculationConvergence)expected.CalculationConvergence, actual.CalculationConvergence);

            AssertGeneralResult(expected.GeneralResultSubMechanismIllustrationPointEntity, actual.GeneralResult);
        }
Ejemplo n.º 11
0
        public void Read_EntityWithIllustrationPoints_ReturnsHydraulicBoundaryLocationCalculationOutputWithGeneralResult()
        {
            // Setup
            var random = new Random(21);

            var stochastEntities = new[]
            {
                new StochastEntity
                {
                    Name     = "stochastEntityOne",
                    Duration = random.NextDouble(),
                    Alpha    = random.NextDouble(),
                    Order    = 0
                }
            };
            var topLevelIllustrationPointEntities = new[]
            {
                new TopLevelSubMechanismIllustrationPointEntity
                {
                    WindDirectionName  = "WindDirectionTwo",
                    WindDirectionAngle = random.NextDouble(),
                    ClosingSituation   = "ClosingSituationTwo",
                    SubMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity
                    {
                        Beta = random.NextDouble(),
                        Name = "IllustrationPointTwo"
                    },
                    Order = 0
                }
            };

            var entity = new HydraulicLocationOutputEntity
            {
                Result                 = double.NaN,
                TargetProbability      = double.NaN,
                TargetReliability      = double.NaN,
                CalculatedProbability  = double.NaN,
                CalculatedReliability  = double.NaN,
                CalculationConvergence = Convert.ToByte(random.NextEnumValue <CalculationConvergence>()),
                GeneralResultSubMechanismIllustrationPointEntity = new GeneralResultSubMechanismIllustrationPointEntity
                {
                    GoverningWindDirectionName  = "SSE",
                    GoverningWindDirectionAngle = random.NextDouble(),
                    StochastEntities            = stochastEntities,
                    TopLevelSubMechanismIllustrationPointEntities = topLevelIllustrationPointEntities
                }
            };

            // Call
            HydraulicBoundaryLocationCalculationOutput output = entity.Read();

            // Assert
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult       = output.GeneralResult;
            GeneralResultSubMechanismIllustrationPointEntity      generalResultEntity =
                entity.GeneralResultSubMechanismIllustrationPointEntity;

            AssertWindDirection(generalResultEntity, generalResult.GoverningWindDirection);
            AssertStochasts(generalResultEntity.StochastEntities.ToArray(), generalResult.Stochasts.ToArray());
            AssertIllustrationPoints(generalResultEntity.TopLevelSubMechanismIllustrationPointEntities.ToArray(),
                                     generalResult.TopLevelIllustrationPoints.ToArray());
        }