示例#1
0
        public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
        {
            // Setup
            var          random      = new Random(31);
            const string name        = "some name";
            double       bottom      = -random.NextDouble();
            var          soilProfile = new MacroStabilityInwardsSoilProfile1D(name, bottom, new[]
            {
                new MacroStabilityInwardsSoilLayer1D(random.NextDouble()),
                new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
            });
            var registry = new PersistenceRegistry();

            // Call
            MacroStabilityInwardsSoilProfileOneDEntity entity = soilProfile.Create(registry);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(soilProfile.Bottom, entity.Bottom);
            Assert.AreEqual(soilProfile.Layers.Count(), entity.MacroStabilityInwardsSoilLayerOneDEntities.Count);

            MacroStabilityInwardsSoilLayerOneDEntity firstLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(0);

            Assert.AreEqual(soilProfile.Layers.ElementAt(0).Top, firstLayerEntity.Top);

            MacroStabilityInwardsSoilLayerOneDEntity secondLayerEntity = entity.MacroStabilityInwardsSoilLayerOneDEntities.ElementAt(1);

            Assert.AreEqual(soilProfile.Layers.ElementAt(1).Top, secondLayerEntity.Top);
        }
示例#2
0
        /// <summary>
        /// Reads the <see cref="MacroStabilityInwardsSoilLayerOneDEntity"/> and use the information
        /// to construct a <see cref="MacroStabilityInwardsSoilLayer1D"/>.
        /// </summary>
        /// <param name="entity">The <see cref="MacroStabilityInwardsSoilLayerOneDEntity"/> to create
        /// <see cref="MacroStabilityInwardsSoilLayer1D"/> for.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilLayer1D"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/> is <c>null</c>.</exception>
        public static MacroStabilityInwardsSoilLayer1D Read(this MacroStabilityInwardsSoilLayerOneDEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(new MacroStabilityInwardsSoilLayer1D(entity.Top.ToNullAsNaN(), ReadData(entity)));
        }
示例#3
0
 private static MacroStabilityInwardsSoilLayerData ReadData(MacroStabilityInwardsSoilLayerOneDEntity entity)
 {
     return(new MacroStabilityInwardsSoilLayerData
     {
         IsAquifer = Convert.ToBoolean(entity.IsAquifer),
         MaterialName = entity.MaterialName ?? string.Empty,
         Color = entity.Color.ToColor(),
         UsePop = Convert.ToBoolean(entity.UsePop),
         ShearStrengthModel = (MacroStabilityInwardsShearStrengthModel)entity.ShearStrengthModel,
         AbovePhreaticLevel =
         {
             Mean                   = (RoundedDouble)entity.AbovePhreaticLevelMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.AbovePhreaticLevelCoefficientOfVariation.ToNullAsNaN(),
             Shift                  = (RoundedDouble)entity.AbovePhreaticLevelShift.ToNullAsNaN()
         },
         BelowPhreaticLevel =
         {
             Mean                   = (RoundedDouble)entity.BelowPhreaticLevelMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.BelowPhreaticLevelCoefficientOfVariation.ToNullAsNaN(),
             Shift                  = (RoundedDouble)entity.BelowPhreaticLevelShift.ToNullAsNaN()
         },
         Cohesion =
         {
             Mean                   = (RoundedDouble)entity.CohesionMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.CohesionCoefficientOfVariation.ToNullAsNaN()
         },
         FrictionAngle =
         {
             Mean                   = (RoundedDouble)entity.FrictionAngleMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.FrictionAngleCoefficientOfVariation.ToNullAsNaN()
         },
         ShearStrengthRatio =
         {
             Mean                   = (RoundedDouble)entity.ShearStrengthRatioMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.ShearStrengthRatioCoefficientOfVariation.ToNullAsNaN()
         },
         StrengthIncreaseExponent =
         {
             Mean                   = (RoundedDouble)entity.StrengthIncreaseExponentMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.StrengthIncreaseExponentCoefficientOfVariation.ToNullAsNaN()
         },
         Pop =
         {
             Mean                   = (RoundedDouble)entity.PopMean.ToNullAsNaN(),
             CoefficientOfVariation = (RoundedDouble)entity.PopCoefficientOfVariation.ToNullAsNaN()
         }
     });
 }
        public void Create_StringPropertiesDoNotShareReference()
        {
            // Setup
            const string materialName = "MaterialName";
            var          soilLayer    = new MacroStabilityInwardsSoilLayer1D(0)
            {
                Data =
                {
                    MaterialName = materialName
                }
            };

            // Call
            MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(0);

            // Assert
            TestHelper.AssertAreEqualButNotSame(materialName, entity.MaterialName);
        }
示例#5
0
        public void Read_WithNullValues_ReturnsMacroStabilityInwardsSoilLayer1DWithNaNValues()
        {
            // Setup
            var entity = new MacroStabilityInwardsSoilLayerOneDEntity
            {
                MaterialName = nameof(MacroStabilityInwardsSoilLayerOneDEntity)
            };

            // Call
            MacroStabilityInwardsSoilLayer1D layer = entity.Read();

            // Assert
            Assert.IsNotNull(layer);
            MacroStabilityInwardsSoilLayerData data = layer.Data;

            Assert.AreEqual(entity.MaterialName, data.MaterialName);

            Assert.IsNaN(layer.Top);

            Assert.IsNaN(data.AbovePhreaticLevel.Mean);
            Assert.IsNaN(data.AbovePhreaticLevel.CoefficientOfVariation);
            Assert.IsNaN(data.AbovePhreaticLevel.Shift);

            Assert.IsNaN(data.BelowPhreaticLevel.Mean);
            Assert.IsNaN(data.BelowPhreaticLevel.CoefficientOfVariation);
            Assert.IsNaN(data.BelowPhreaticLevel.Shift);

            Assert.IsNaN(data.Cohesion.Mean);
            Assert.IsNaN(data.Cohesion.CoefficientOfVariation);

            Assert.IsNaN(data.FrictionAngle.Mean);
            Assert.IsNaN(data.FrictionAngle.CoefficientOfVariation);

            Assert.IsNaN(data.ShearStrengthRatio.Mean);
            Assert.IsNaN(data.ShearStrengthRatio.CoefficientOfVariation);

            Assert.IsNaN(data.StrengthIncreaseExponent.Mean);
            Assert.IsNaN(data.StrengthIncreaseExponent.CoefficientOfVariation);

            Assert.IsNaN(data.Pop.Mean);
            Assert.IsNaN(data.Pop.CoefficientOfVariation);
        }
        public void Create_WithValidProperties_ReturnsEntityWithPropertiesSet()
        {
            // Setup
            var random    = new Random(31);
            var soilLayer = new MacroStabilityInwardsSoilLayer1D(random.NextDouble())
            {
                Data =
                {
                    IsAquifer          = random.NextBoolean(),
                    MaterialName       = "MaterialName",
                    Color              = Color.FromKnownColor(random.NextEnumValue <KnownColor>()),
                    UsePop             = random.NextBoolean(),
                    ShearStrengthModel = random.NextEnumValue <MacroStabilityInwardsShearStrengthModel>(),
                    AbovePhreaticLevel =
                    {
                        Mean                   = (RoundedDouble)0.3,
                        CoefficientOfVariation = (RoundedDouble)0.2,
                        Shift                  = (RoundedDouble)0.1
                    },
                    BelowPhreaticLevel         =
                    {
                        Mean                   = (RoundedDouble)10,
                        CoefficientOfVariation = (RoundedDouble)0.5,
                        Shift                  = (RoundedDouble)2
                    },
                    Cohesion                   =
                    {
                        Mean                   = (RoundedDouble)10,
                        CoefficientOfVariation = (RoundedDouble)1
                    },
                    FrictionAngle              =
                    {
                        Mean                   = (RoundedDouble)12,
                        CoefficientOfVariation = (RoundedDouble)0.8
                    },
                    ShearStrengthRatio         =
                    {
                        Mean                   = (RoundedDouble)10,
                        CoefficientOfVariation = (RoundedDouble)0.6
                    },
                    StrengthIncreaseExponent   =
                    {
                        Mean                   = (RoundedDouble)11,
                        CoefficientOfVariation = (RoundedDouble)0.7
                    },
                    Pop                        =
                    {
                        Mean                   = (RoundedDouble)14,
                        CoefficientOfVariation = (RoundedDouble)0.9
                    }
                }
            };
            int order = random.Next();

            // Call
            MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(order);

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(soilLayer.Top, entity.Top);

            MacroStabilityInwardsSoilLayerData data = soilLayer.Data;

            Assert.AreEqual(Convert.ToByte(data.IsAquifer), entity.IsAquifer);
            Assert.AreEqual(data.MaterialName, entity.MaterialName);
            Assert.AreEqual(data.Color.ToInt64(), Convert.ToInt64(entity.Color));
            Assert.AreEqual(Convert.ToByte(data.UsePop), entity.UsePop);
            Assert.AreEqual(Convert.ToByte(data.ShearStrengthModel), entity.ShearStrengthModel);

            VariationCoefficientLogNormalDistribution abovePhreaticLevelDistribution = data.AbovePhreaticLevel;

            Assert.AreEqual(abovePhreaticLevelDistribution.Mean, entity.AbovePhreaticLevelMean,
                            abovePhreaticLevelDistribution.GetAccuracy());
            Assert.AreEqual(abovePhreaticLevelDistribution.CoefficientOfVariation, entity.AbovePhreaticLevelCoefficientOfVariation,
                            abovePhreaticLevelDistribution.GetAccuracy());
            Assert.AreEqual(abovePhreaticLevelDistribution.Shift, entity.AbovePhreaticLevelShift,
                            abovePhreaticLevelDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution belowPhreaticLevelDistribution = data.BelowPhreaticLevel;

            Assert.AreEqual(belowPhreaticLevelDistribution.Mean, entity.BelowPhreaticLevelMean,
                            belowPhreaticLevelDistribution.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelDistribution.CoefficientOfVariation, entity.BelowPhreaticLevelCoefficientOfVariation,
                            belowPhreaticLevelDistribution.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelDistribution.Shift, entity.BelowPhreaticLevelShift,
                            belowPhreaticLevelDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution cohesionDistribution = data.Cohesion;

            Assert.AreEqual(cohesionDistribution.Mean, entity.CohesionMean,
                            cohesionDistribution.GetAccuracy());
            Assert.AreEqual(cohesionDistribution.CoefficientOfVariation, entity.CohesionCoefficientOfVariation,
                            cohesionDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution frictionAngleDistribution = data.FrictionAngle;

            Assert.AreEqual(frictionAngleDistribution.Mean, entity.FrictionAngleMean,
                            frictionAngleDistribution.GetAccuracy());
            Assert.AreEqual(frictionAngleDistribution.CoefficientOfVariation, entity.FrictionAngleCoefficientOfVariation,
                            frictionAngleDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution shearStrengthRatioDistribution = data.ShearStrengthRatio;

            Assert.AreEqual(shearStrengthRatioDistribution.Mean, entity.ShearStrengthRatioMean,
                            shearStrengthRatioDistribution.GetAccuracy());
            Assert.AreEqual(shearStrengthRatioDistribution.CoefficientOfVariation, entity.ShearStrengthRatioCoefficientOfVariation,
                            shearStrengthRatioDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution strengthIncreaseExponentDistribution = data.StrengthIncreaseExponent;

            Assert.AreEqual(strengthIncreaseExponentDistribution.Mean, entity.StrengthIncreaseExponentMean,
                            strengthIncreaseExponentDistribution.GetAccuracy());
            Assert.AreEqual(strengthIncreaseExponentDistribution.CoefficientOfVariation, entity.StrengthIncreaseExponentCoefficientOfVariation,
                            strengthIncreaseExponentDistribution.GetAccuracy());

            VariationCoefficientLogNormalDistribution popDistribution = data.Pop;

            Assert.AreEqual(popDistribution.Mean, entity.PopMean, popDistribution.GetAccuracy());
            Assert.AreEqual(popDistribution.CoefficientOfVariation, entity.PopCoefficientOfVariation, popDistribution.GetAccuracy());
            Assert.AreEqual(order, entity.Order);
        }
        public void Create_WithNaNProperties_ReturnsEntityWithPropertiesSetToNull()
        {
            // Setup
            var soilLayer = new MacroStabilityInwardsSoilLayer1D(double.NaN)
            {
                Data =
                {
                    AbovePhreaticLevel         =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN,
                        Shift                  = RoundedDouble.NaN
                    },
                    BelowPhreaticLevel         =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN,
                        Shift                  = RoundedDouble.NaN
                    },
                    Cohesion                   =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN
                    },
                    FrictionAngle              =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN
                    },
                    ShearStrengthRatio         =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN
                    },
                    StrengthIncreaseExponent   =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN
                    },
                    Pop                        =
                    {
                        Mean                   = RoundedDouble.NaN,
                        CoefficientOfVariation = RoundedDouble.NaN
                    }
                }
            };

            // Call
            MacroStabilityInwardsSoilLayerOneDEntity entity = soilLayer.Create(0);

            // Assert
            Assert.IsNotNull(entity);
            Assert.IsNull(entity.Top);
            Assert.IsNull(entity.AbovePhreaticLevelMean);
            Assert.IsNull(entity.AbovePhreaticLevelCoefficientOfVariation);
            Assert.IsNull(entity.AbovePhreaticLevelShift);
            Assert.IsNull(entity.BelowPhreaticLevelMean);
            Assert.IsNull(entity.BelowPhreaticLevelCoefficientOfVariation);
            Assert.IsNull(entity.BelowPhreaticLevelShift);
            Assert.IsNull(entity.CohesionMean);
            Assert.IsNull(entity.CohesionCoefficientOfVariation);
            Assert.IsNull(entity.FrictionAngleMean);
            Assert.IsNull(entity.FrictionAngleCoefficientOfVariation);
            Assert.IsNull(entity.ShearStrengthRatioMean);
            Assert.IsNull(entity.ShearStrengthRatioCoefficientOfVariation);
            Assert.IsNull(entity.StrengthIncreaseExponentMean);
            Assert.IsNull(entity.StrengthIncreaseExponentCoefficientOfVariation);
            Assert.IsNull(entity.PopMean);
            Assert.IsNull(entity.PopCoefficientOfVariation);
        }
示例#8
0
        public void Read_WithValues_ReturnsMacroStabilityInwardsSoilLayer1DWithDoubleParameterValues()
        {
            // Setup
            var          random    = new Random(31);
            double       top       = random.NextDouble();
            Color        color     = Color.FromKnownColor(random.NextEnumValue <KnownColor>());
            bool         isAquifer = random.NextBoolean();
            const double abovePhreaticLevelMean = 0.3;
            const double abovePhreaticLevelCoefficientOfVariation = 0.2;
            const double abovePhreaticLevelShift = 0.1;
            const double belowPhreaticLevelMean  = 0.6;
            const double belowPhreaticLevelCoefficientOfVariation = 0.5;
            const double belowPhreaticLevelShift                        = 0.4;
            double       cohesionMean                                   = random.NextDouble();
            double       cohesionCoefficientOfVariation                 = random.NextDouble();
            double       frictionAngleMean                              = random.NextDouble();
            double       frictionAngleCoefficientOfVariation            = random.NextDouble();
            double       shearStrengthRatioMean                         = random.NextDouble();
            double       shearStrengthRatioCoefficientOfVariation       = random.NextDouble();
            double       strengthIncreaseExponentMean                   = random.NextDouble();
            double       strengthIncreaseExponentCoefficientOfVariation = random.NextDouble();
            double       popMean = random.NextDouble();
            double       popCoefficientOfVariation = random.NextDouble();

            var entity = new MacroStabilityInwardsSoilLayerOneDEntity
            {
                Top                    = top,
                IsAquifer              = Convert.ToByte(isAquifer),
                Color                  = color.ToInt64(),
                MaterialName           = random.Next().ToString(),
                AbovePhreaticLevelMean = abovePhreaticLevelMean,
                AbovePhreaticLevelCoefficientOfVariation = abovePhreaticLevelCoefficientOfVariation,
                AbovePhreaticLevelShift = abovePhreaticLevelShift,
                BelowPhreaticLevelMean  = belowPhreaticLevelMean,
                BelowPhreaticLevelCoefficientOfVariation = belowPhreaticLevelCoefficientOfVariation,
                BelowPhreaticLevelShift                        = belowPhreaticLevelShift,
                CohesionMean                                   = cohesionMean,
                CohesionCoefficientOfVariation                 = cohesionCoefficientOfVariation,
                FrictionAngleMean                              = frictionAngleMean,
                FrictionAngleCoefficientOfVariation            = frictionAngleCoefficientOfVariation,
                ShearStrengthRatioMean                         = shearStrengthRatioMean,
                ShearStrengthRatioCoefficientOfVariation       = shearStrengthRatioCoefficientOfVariation,
                StrengthIncreaseExponentMean                   = strengthIncreaseExponentMean,
                StrengthIncreaseExponentCoefficientOfVariation = strengthIncreaseExponentCoefficientOfVariation,
                PopMean = popMean,
                PopCoefficientOfVariation = popCoefficientOfVariation
            };

            // Call
            MacroStabilityInwardsSoilLayer1D layer = entity.Read();

            // Assert
            Assert.IsNotNull(layer);
            Assert.AreEqual(top, layer.Top);
            MacroStabilityInwardsSoilLayerData data = layer.Data;

            Assert.AreEqual(isAquifer, data.IsAquifer);
            Assert.IsNotNull(color);
            Assert.AreEqual(color.ToArgb(), data.Color.ToArgb());
            Assert.AreEqual(entity.MaterialName, data.MaterialName);

            Assert.AreEqual(abovePhreaticLevelMean, data.AbovePhreaticLevel.Mean,
                            data.AbovePhreaticLevel.GetAccuracy());
            Assert.AreEqual(abovePhreaticLevelCoefficientOfVariation, data.AbovePhreaticLevel.CoefficientOfVariation,
                            data.AbovePhreaticLevel.GetAccuracy());
            Assert.AreEqual(abovePhreaticLevelShift, data.AbovePhreaticLevel.Shift,
                            data.AbovePhreaticLevel.GetAccuracy());

            Assert.AreEqual(belowPhreaticLevelMean, data.BelowPhreaticLevel.Mean,
                            data.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelCoefficientOfVariation, data.BelowPhreaticLevel.CoefficientOfVariation,
                            data.BelowPhreaticLevel.GetAccuracy());
            Assert.AreEqual(belowPhreaticLevelShift, data.BelowPhreaticLevel.Shift,
                            data.BelowPhreaticLevel.GetAccuracy());

            Assert.AreEqual(cohesionMean, data.Cohesion.Mean,
                            data.Cohesion.GetAccuracy());
            Assert.AreEqual(cohesionCoefficientOfVariation, data.Cohesion.CoefficientOfVariation,
                            data.Cohesion.GetAccuracy());

            Assert.AreEqual(frictionAngleMean, data.FrictionAngle.Mean,
                            data.FrictionAngle.GetAccuracy());
            Assert.AreEqual(frictionAngleCoefficientOfVariation, data.FrictionAngle.CoefficientOfVariation,
                            data.FrictionAngle.GetAccuracy());

            Assert.AreEqual(shearStrengthRatioMean, data.ShearStrengthRatio.Mean,
                            data.ShearStrengthRatio.GetAccuracy());
            Assert.AreEqual(shearStrengthRatioCoefficientOfVariation, data.ShearStrengthRatio.CoefficientOfVariation,
                            data.ShearStrengthRatio.GetAccuracy());

            Assert.AreEqual(strengthIncreaseExponentMean, data.StrengthIncreaseExponent.Mean,
                            data.StrengthIncreaseExponent.GetAccuracy());
            Assert.AreEqual(strengthIncreaseExponentCoefficientOfVariation, data.StrengthIncreaseExponent.CoefficientOfVariation,
                            data.StrengthIncreaseExponent.GetAccuracy());

            Assert.AreEqual(popMean, data.Pop.Mean, data.Pop.GetAccuracy());
            Assert.AreEqual(popCoefficientOfVariation, data.Pop.CoefficientOfVariation,
                            data.Pop.GetAccuracy());
        }