/// <summary> /// Creates <see cref="LayerWithSoil"/> objects based on <paramref name="soilProfile"/>. /// </summary> /// <param name="soilProfile">The <see cref="Calculators.Input.SoilProfile"/> to create <see cref="LayerWithSoil"/> objects for.</param> /// <param name="layerLookup">The lookup to fill with the created layers.</param> /// <returns>An <see cref="Array"/> of <see cref="LayerWithSoil"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="soilProfile"/> is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <see cref="ShearStrengthModel"/>, /// <see cref="Calculators.Input.WaterPressureInterpolationModel"/> is an invalid value.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="ShearStrengthModel"/>, /// <see cref="Calculators.Input.WaterPressureInterpolationModel"/> is a valid value, but unsupported.</exception> public static LayerWithSoil[] Create(SoilProfile soilProfile, out IDictionary <SoilLayer, LayerWithSoil> layerLookup) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } layerLookup = new Dictionary <SoilLayer, LayerWithSoil>(); return(GetLayersWithSoilRecursively(soilProfile.Layers, layerLookup).ToArray()); }
public void Create_ValidWaterPressureInterpolationModel_ExpectedWaterPressureInterpolationModel( WaterPressureInterpolationModel waterPressureInterpolationModel, CSharpWrapperWaterPressureInterpolationModel expectedWaterPressureInterpolationModel) { // Setup var profile = new SoilProfile(new[] { new SoilLayer(new Point2D[0], new SoilLayer.ConstructionProperties { WaterPressureInterpolationModel = waterPressureInterpolationModel }, Enumerable.Empty <SoilLayer>()) }, Enumerable.Empty <PreconsolidationStress>()); // Call LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(profile, out IDictionary <SoilLayer, LayerWithSoil> _); // Assert Assert.AreEqual(expectedWaterPressureInterpolationModel, layersWithSoil[0].WaterPressureInterpolationModel); }
public void Create_InvalidWaterPressureInterpolationModel_ThrowInvalidEnumArgumentException() { // Setup var profile = new SoilProfile(new[] { new SoilLayer(new Point2D[0], new SoilLayer.ConstructionProperties { WaterPressureInterpolationModel = (WaterPressureInterpolationModel)99 }, Enumerable.Empty <SoilLayer>()) }, Enumerable.Empty <PreconsolidationStress>()); // Call void Call() => LayerWithSoilCreator.Create(profile, out IDictionary <SoilLayer, LayerWithSoil> _); // Assert string message = $"The value of argument 'waterPressureInterpolationModel' ({99}) is invalid for Enum type '{nameof(WaterPressureInterpolationModel)}'."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, message); }
public void Create_ValidShearStrengthModel_ExpectedShearStrengthModel( ShearStrengthModel shearStrengthModel, ShearStrengthModelType expectedShearStrengthAbovePhreaticLevelModel, ShearStrengthModelType expectedShearStrengthBelowPhreaticLevelModel) { // Setup var profile = new SoilProfile(new[] { new SoilLayer(new Point2D[0], new SoilLayer.ConstructionProperties { ShearStrengthModel = shearStrengthModel }, Enumerable.Empty <SoilLayer>()) }, Enumerable.Empty <PreconsolidationStress>()); // Call LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(profile, out IDictionary <SoilLayer, LayerWithSoil> _); // Assert Assert.AreEqual(expectedShearStrengthAbovePhreaticLevelModel, layersWithSoil[0].Soil.ShearStrengthAbovePhreaticLevelModel); Assert.AreEqual(expectedShearStrengthBelowPhreaticLevelModel, layersWithSoil[0].Soil.ShearStrengthBelowPhreaticLevelModel); }
public void Create_SoilProfile_ExpectedLayersWithSoil() { // Setup var outerRing1 = new Point2D[0]; var outerRing2 = new Point2D[0]; var outerRing3 = new Point2D[0]; var outerRing4 = new Point2D[0]; var outerRing5 = new Point2D[0]; var outerRing6 = new Point2D[0]; var soilProfile = new SoilProfile ( new[] { new SoilLayer(outerRing1, CreateRandomConstructionProperties(21, "Material 1"), new[] { new SoilLayer(outerRing2, CreateRandomConstructionProperties(22, "Material 2"), new[] { new SoilLayer(outerRing3, CreateRandomConstructionProperties(22, "Material 3"), Enumerable.Empty <SoilLayer>()) }), new SoilLayer(outerRing4, CreateRandomConstructionProperties(23, "Material 4"), Enumerable.Empty <SoilLayer>()) }), new SoilLayer(outerRing5, CreateRandomConstructionProperties(24, "Material 5"), new[] { new SoilLayer(outerRing6, CreateRandomConstructionProperties(25, "Material 6"), Enumerable.Empty <SoilLayer>()) }) }, Enumerable.Empty <PreconsolidationStress>() ); // Call LayerWithSoil[] layersWithSoil = LayerWithSoilCreator.Create(soilProfile, out IDictionary <SoilLayer, LayerWithSoil> layerLookup); // Assert SoilLayer layer1 = soilProfile.Layers.ElementAt(0); SoilLayer layer2 = layer1.NestedLayers.ElementAt(0); SoilLayer layer3 = layer2.NestedLayers.ElementAt(0); SoilLayer layer4 = layer1.NestedLayers.ElementAt(1); SoilLayer layer5 = soilProfile.Layers.ElementAt(1); SoilLayer layer6 = layer5.NestedLayers.ElementAt(0); Assert.AreEqual(6, layersWithSoil.Length); Assert.AreEqual(outerRing1, layersWithSoil[0].OuterRing); CollectionAssert.AreEqual(new[] { outerRing2, outerRing3, outerRing4 }, layersWithSoil[0].InnerRings); AssertSoilLayerProperties(layer1, layersWithSoil[0]); Assert.AreEqual(outerRing2, layersWithSoil[1].OuterRing); CollectionAssert.AreEqual(new[] { outerRing3 }, layersWithSoil[1].InnerRings); AssertSoilLayerProperties(layer2, layersWithSoil[1]); Assert.AreEqual(outerRing3, layersWithSoil[2].OuterRing); CollectionAssert.IsEmpty(layersWithSoil[2].InnerRings); AssertSoilLayerProperties(layer3, layersWithSoil[2]); Assert.AreEqual(outerRing4, layersWithSoil[3].OuterRing); CollectionAssert.IsEmpty(layersWithSoil[3].InnerRings); AssertSoilLayerProperties(layer4, layersWithSoil[3]); Assert.AreEqual(outerRing5, layersWithSoil[4].OuterRing); CollectionAssert.AreEqual(new[] { outerRing6 }, layersWithSoil[4].InnerRings); AssertSoilLayerProperties(layer5, layersWithSoil[4]); Assert.AreEqual(outerRing6, layersWithSoil[5].OuterRing); CollectionAssert.IsEmpty(layersWithSoil[5].InnerRings); AssertSoilLayerProperties(layer6, layersWithSoil[5]); SoilLayer[] originalSoilLayers = { layer1, layer2, layer3, layer4, layer5, layer6 }; Assert.AreEqual(layersWithSoil.Length, layerLookup.Count); for (var i = 0; i < layersWithSoil.Length; i++) { Assert.AreSame(originalSoilLayers[i], layerLookup.ElementAt(i).Key); Assert.AreSame(layersWithSoil.ElementAt(i), layerLookup.ElementAt(i).Value); } }