public void Transform_SoilProfile1DWithMultipleLayers_ReturnsProfileWithBottomAndALayer() { // Setup const string profileName = "SomeProfile"; var random = new Random(22); double bottom = random.NextDouble(); double top = bottom + random.NextDouble(); double top2 = bottom + random.NextDouble(); const long pipingSoilProfileId = 1234L; var profile = new SoilProfile1D(pipingSoilProfileId, profileName, bottom, new[] { SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer(top), SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer(top2) } ); // Call PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(profileName, transformed.Name); Assert.AreEqual(2, transformed.Layers.Count()); Assert.AreEqual(bottom, transformed.Bottom); }
public void Transform_InvalidSoilProfile1D_ThrowsImportedDataTransformException() { // Setup const string profileName = "SomeProfile"; var random = new Random(22); double bottom = random.NextDouble(); const long pipingSoilProfileId = 1234L; var profile = new SoilProfile1D(pipingSoilProfileId, profileName, bottom, Enumerable.Empty <SoilLayer1D>()); // Call TestDelegate call = () => PipingSoilProfileTransformer.Transform(profile); // Assert var exception = Assert.Throws <ImportedDataTransformException>(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf <ArgumentException>(innerException); string expectedMessage = CreateExpectedErrorMessage(profileName, innerException.Message); Assert.AreEqual(expectedMessage, exception.Message); }
public void Transform_SoilProfile1DWithSingleLayer_ReturnsProfileWithBottomAndALayer() { // Setup const string profileName = "SomeProfile"; var random = new Random(22); double bottom = random.NextDouble(); double top = random.NextDouble(); const long pipingSoilProfileId = 1234L; var profile = new SoilProfile1D(pipingSoilProfileId, profileName, bottom, new[] { SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer(top) } ); // Call PipingSoilProfile transformed = PipingSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(profileName, transformed.Name); Assert.AreEqual(SoilProfileType.SoilProfile1D, transformed.SoilProfileSourceType); PipingSoilLayer[] layers = transformed.Layers.ToArray(); Assert.AreEqual(1, layers.Length); Assert.AreEqual(top, layers[0].Top); Assert.AreEqual(bottom, transformed.Bottom); }
public void ReadSoilProfile_BottomAboveLayers_ReturnsProfileWithExpectedBottomAndTopValues() { // Setup string dbFile = Path.Combine(testDataPath, "1dprofileWithIncorrectBottom.soil"); using (var reader = new SoilProfile1DReader(dbFile)) { reader.Initialize(); // Call SoilProfile1D profile = reader.ReadSoilProfile(); // Assert Assert.AreEqual(9999999, profile.Bottom); CollectionAssert.AreEqual(new[] { 1.1, 2.2, 3.3 }, profile.Layers.Select(layer => layer.Top)); } Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); }
/// <summary> /// Transforms the generic <paramref name="soilProfile"/> into a /// <see cref="MacroStabilityInwardsSoilProfile1D"/>. /// </summary> /// <param name="soilProfile">The soil profile to use in the transformation.</param> /// <returns>A <see cref="MacroStabilityInwardsSoilProfile1D"/> based on the given data.</returns> /// <exception cref="ImportedDataTransformException">Thrown when <paramref name="soilProfile"/> cannot be /// transformed in a <see cref="MacroStabilityInwardsSoilProfile1D"/>.</exception> private static MacroStabilityInwardsSoilProfile1D Transform(SoilProfile1D soilProfile) { try { return(new MacroStabilityInwardsSoilProfile1D(soilProfile.Name, soilProfile.Bottom, soilProfile.Layers .Select(MacroStabilityInwardsSoilLayerTransformer.Transform) .ToArray())); } catch (ArgumentException e) { string errorMessage = CreateErrorMessage(soilProfile.Name, e.Message); throw new ImportedDataTransformException(errorMessage, e); } }
public void Transform_ValidSoilProfile1D_ReturnMacroStabilityInwardsSoilProfile1D() { // Setup var profile = new SoilProfile1D(1, "test", 3, new[] { SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer() }); // Call var transformedProfile = (MacroStabilityInwardsSoilProfile1D)MacroStabilityInwardsSoilProfileTransformer.Transform(profile); // Assert Assert.AreEqual(profile.Name, transformedProfile.Name); Assert.AreEqual(profile.Bottom, transformedProfile.Bottom); Assert.AreEqual(profile.Layers.Count(), transformedProfile.Layers.Count()); CollectionAssert.AllItemsAreInstancesOfType(transformedProfile.Layers, typeof(MacroStabilityInwardsSoilLayer1D)); }
/// <summary> /// Creates a <see cref="PipingSoilProfile"/> based on the information of <see cref="SoilProfile1D"/> /// </summary> /// <param name="soilProfile1D">The soil profile to use in the transformation.</param> /// <returns>The created <see cref="PipingSoilProfile"/>.</returns> /// <exception cref="ImportedDataTransformException">Thrown when the <paramref name="soilProfile1D"/> /// cannot be transformed in a <see cref="PipingSoilProfile"/>.</exception> private static PipingSoilProfile CreatePipingSoilProfile(SoilProfile1D soilProfile1D) { IEnumerable <PipingSoilLayer> layers = soilProfile1D.Layers.Select(PipingSoilLayerTransformer.Transform).ToArray(); try { return(new PipingSoilProfile(soilProfile1D.Name, soilProfile1D.Bottom, layers, SoilProfileType.SoilProfile1D)); } catch (ArgumentException e) { string errorMessage = CreateErrorMessage(soilProfile1D.Name, e.Message); throw new ImportedDataTransformException(errorMessage, e); } }
public void Transform_InvalidSoilProfile1D_ThrowsImportedDataTransformException() { // Setup var profile = new SoilProfile1D(1, "test", 3, Enumerable.Empty <SoilLayer1D>()); // Call TestDelegate call = () => MacroStabilityInwardsSoilProfileTransformer.Transform(profile); // Assert var exception = Assert.Throws <ImportedDataTransformException>(call); Exception innerException = exception.InnerException; Assert.IsInstanceOf <ArgumentException>(innerException); string expectedMessage = CreateExpectedErrorMessage(profile.Name, innerException.Message); Assert.AreEqual(expectedMessage, exception.Message); }
public void ReadSoilProfile_Empty1DProfileWithoutLayers_ReturnsProfile() { // Setup string dbFile = Path.Combine(testDataPath, "1dprofileNoLayers.soil"); using (var reader = new SoilProfile1DReader(dbFile)) { reader.Initialize(); // Call SoilProfile1D profile = reader.ReadSoilProfile(); // Assert Assert.AreEqual("Schematisering1", profile.Name); Assert.AreEqual(1, profile.Id); Assert.IsNaN(profile.Bottom); CollectionAssert.IsEmpty(profile.Layers); } }
public void Constructor_ValidArguments_ReturnsExpectedProperties(double bottomOffset) { // Setup const long id = 123; const string name = "some name"; const int bottom = 1; var soilLayer1Ds = new[] { new SoilLayer1D(bottom + bottomOffset) }; // Call var soilProfile1D = new SoilProfile1D(id, name, bottom, soilLayer1Ds); // Assert Assert.IsInstanceOf <ISoilProfile>(soilProfile1D); Assert.AreEqual(id, soilProfile1D.Id); Assert.AreEqual(name, soilProfile1D.Name); Assert.AreEqual(bottom, soilProfile1D.Bottom); Assert.AreSame(soilLayer1Ds, soilProfile1D.Layers); }
public void Transform_ValidStochasticSoilModelWithSimilarProfileInTwoStochasticSoilProfiles_ReturnsExpectedPipingStochasticSoilModel() { // Setup var random = new Random(21); const string soilProfileName = "SoilProfile"; const double intersectionX = 1.0; var soilProfile2D = new SoilProfile2D(0, soilProfileName, new[] { SoilLayer2DTestFactory.CreateSoilLayer2D() }, Enumerable.Empty <PreconsolidationStress>()) { IntersectionX = intersectionX }; var stochasticSoilProfile2D = new StochasticSoilProfile(random.NextDouble(), soilProfile2D); var soilProfile1D = new SoilProfile1D(0, soilProfileName, 0, new[] { SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer() }); var stochasticSoilProfile1D = new StochasticSoilProfile(random.NextDouble(), soilProfile1D); var transformer = new PipingStochasticSoilModelTransformer(); StochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[] { stochasticSoilProfile2D, stochasticSoilProfile1D }); // Call PipingStochasticSoilModel transformed = transformer.Transform(soilModel); // Assert PipingStochasticSoilProfile[] transformedStochasticSoilProfiles = transformed.StochasticSoilProfiles.ToArray(); Assert.AreEqual(2, transformedStochasticSoilProfiles.Length); Assert.AreEqual(stochasticSoilProfile2D.Probability, transformedStochasticSoilProfiles[0].Probability, 1e-6); Assert.AreEqual(stochasticSoilProfile1D.Probability, transformedStochasticSoilProfiles[1].Probability, 1e-6); }
public void ReadSoilProfile_DatabaseWith1DProfile1LayerWithAllNullValues_ReturnsProfileWithDefaultValues() { // Setup string dbFile = Path.Combine(testDataPath, "1dprofileWithLayerWithNullValuesOnly.soil"); using (var reader = new SoilProfile1DReader(dbFile)) { reader.Initialize(); // Call SoilProfile1D profile = reader.ReadSoilProfile(); // Assert Assert.AreEqual(1, profile.Bottom); Assert.AreEqual("Schematisering1", profile.Name); SoilLayer1D soilLayer = profile.Layers.Single(); Assert.AreEqual("dummy", soilLayer.MaterialName); Assert.AreEqual(1, soilLayer.Top); Assert.IsNull(soilLayer.IsAquifer); Assert.IsNull(soilLayer.Color); Assert.IsNull(soilLayer.BelowPhreaticLevelDistributionType); Assert.IsNaN(soilLayer.BelowPhreaticLevelMean); Assert.IsNaN(soilLayer.BelowPhreaticLevelDeviation); Assert.IsNaN(soilLayer.BelowPhreaticLevelCoefficientOfVariation); Assert.IsNaN(soilLayer.BelowPhreaticLevelShift); Assert.IsNull(soilLayer.DiameterD70DistributionType); Assert.IsNaN(soilLayer.DiameterD70Mean); Assert.IsNaN(soilLayer.DiameterD70CoefficientOfVariation); Assert.IsNaN(soilLayer.DiameterD70Shift); Assert.IsNull(soilLayer.PermeabilityDistributionType); Assert.IsNaN(soilLayer.PermeabilityMean); Assert.IsNaN(soilLayer.PermeabilityCoefficientOfVariation); Assert.IsNaN(soilLayer.PermeabilityShift); Assert.IsNull(soilLayer.UsePop); Assert.IsNull(soilLayer.ShearStrengthModel); Assert.IsNull(soilLayer.AbovePhreaticLevelDistributionType); Assert.IsNaN(soilLayer.AbovePhreaticLevelMean); Assert.IsNaN(soilLayer.AbovePhreaticLevelCoefficientOfVariation); Assert.IsNaN(soilLayer.AbovePhreaticLevelShift); Assert.IsNull(soilLayer.CohesionDistributionType); Assert.IsNaN(soilLayer.CohesionMean); Assert.IsNaN(soilLayer.CohesionCoefficientOfVariation); Assert.IsNaN(soilLayer.CohesionShift); Assert.IsNull(soilLayer.FrictionAngleDistributionType); Assert.IsNaN(soilLayer.FrictionAngleMean); Assert.IsNaN(soilLayer.FrictionAngleCoefficientOfVariation); Assert.IsNaN(soilLayer.FrictionAngleShift); Assert.IsNull(soilLayer.ShearStrengthRatioDistributionType); Assert.IsNaN(soilLayer.ShearStrengthRatioMean); Assert.IsNaN(soilLayer.ShearStrengthRatioCoefficientOfVariation); Assert.IsNaN(soilLayer.ShearStrengthRatioShift); Assert.IsNull(soilLayer.StrengthIncreaseExponentDistributionType); Assert.IsNaN(soilLayer.StrengthIncreaseExponentMean); Assert.IsNaN(soilLayer.StrengthIncreaseExponentCoefficientOfVariation); Assert.IsNaN(soilLayer.StrengthIncreaseExponentShift); Assert.IsNull(soilLayer.PopDistributionType); Assert.IsNaN(soilLayer.PopMean); Assert.IsNaN(soilLayer.PopCoefficientOfVariation); Assert.IsNaN(soilLayer.PopShift); } Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); }
public void ReadSoilProfile_DatabaseWith1DProfile4Layers_ReturnsProfile() { // Setup string dbFile = Path.Combine(testDataPath, "1dprofile.soil"); using (var reader = new SoilProfile1DReader(dbFile)) { reader.Initialize(); // Call SoilProfile1D profile = reader.ReadSoilProfile(); // Assert Assert.AreEqual(-40, profile.Bottom); Assert.AreEqual("Schematisering1", profile.Name); Assert.AreEqual(4, profile.Layers.Count()); CollectionAssert.AreEqual(new[] { 30, 10, -20, -30 }, profile.Layers.Select(l => l.Top)); CollectionAssert.AreEqual(new[] { "Klei1", "Zand", "dummy", "Klei 3" }, profile.Layers.Select(l => l.MaterialName)); CollectionAssert.AreEqual(new[] { 0.0, 1.0, 1.0, 1.0 }, profile.Layers.Select(l => l.IsAquifer)); CollectionAssert.AreEqual(new[] { -12156236, -65536, -65536, -4144897 }, profile.Layers.Select(l => l.Color)); CollectionAssert.AreEqual(new[] { 2, 2, 2, 2 }, profile.Layers.Select(l => l.BelowPhreaticLevelDistributionType)); CollectionAssert.AreEqual(new[] { 24, 20, 30, 28 }, profile.Layers.Select(l => l.BelowPhreaticLevelMean)); CollectionAssert.AreEqual(new[] { 0.24, 0.2, 0.3, 0.28 }, profile.Layers.Select(l => l.BelowPhreaticLevelDeviation)); CollectionAssert.AreEqual(new[] { 0.01, 0.01, 0.01, 0.01 }, profile.Layers.Select(l => l.BelowPhreaticLevelCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0, 0, 0, 0 }, profile.Layers.Select(l => l.BelowPhreaticLevelShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.DiameterD70DistributionType)); CollectionAssert.AreEqual(new[] { 0.00017, 0.00016, 0.000155, 0.00017 }, profile.Layers.Select(l => l.DiameterD70Mean)); CollectionAssert.AreEqual(new[] { 0.11764705882352941, 0.125, 0.12903225806451615, 0.11764705882352941 }, profile.Layers.Select(l => l.DiameterD70CoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0, 0, 0, 0 }, profile.Layers.Select(l => l.DiameterD70Shift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.PermeabilityDistributionType)); CollectionAssert.AreEqual(new[] { 0, 0.000185, 0.001, 0 }, profile.Layers.Select(l => l.PermeabilityMean)); CollectionAssert.AreEqual(new[] { double.NaN, 0, 0, double.NaN }, profile.Layers.Select(l => l.PermeabilityCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0, 0, 0, 0 }, profile.Layers.Select(l => l.PermeabilityShift)); CollectionAssert.AreEqual(new double?[] { null, null, 0, 0 }, profile.Layers.Select(l => l.UsePop)); CollectionAssert.AreEqual(new double?[] { null, 9, 1, 6 }, profile.Layers.Select(l => l.ShearStrengthModel)); CollectionAssert.AreEqual(new[] { 2, 2, 2, 2 }, profile.Layers.Select(l => l.AbovePhreaticLevelDistributionType)); CollectionAssert.AreEqual(new[] { 14, 10, 20, 18 }, profile.Layers.Select(l => l.AbovePhreaticLevelMean)); CollectionAssert.AreEqual(new[] { 0.01, 0.01, 0.01, 0.01 }, profile.Layers.Select(l => l.AbovePhreaticLevelCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0, 0, 0, 0 }, profile.Layers.Select(l => l.AbovePhreaticLevelShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.CohesionDistributionType)); CollectionAssert.AreEqual(new[] { 1, 7, 4, 3 }, profile.Layers.Select(l => l.CohesionMean)); CollectionAssert.AreEqual(new[] { 0.1, 0.09999999999999999, 0.1, 0.09999999999999999 }, profile.Layers.Select(l => l.CohesionCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0.01, 0.07, 0.04, 0.03 }, profile.Layers.Select(l => l.CohesionShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.FrictionAngleDistributionType)); CollectionAssert.AreEqual(new[] { 11, 77, 44, 33 }, profile.Layers.Select(l => l.FrictionAngleMean)); CollectionAssert.AreEqual(new[] { 0.01, 0.01, 0.01, 0.01 }, profile.Layers.Select(l => l.FrictionAngleCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0.01, 0.07, 0.04, 0.03 }, profile.Layers.Select(l => l.FrictionAngleShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.ShearStrengthRatioDistributionType)); CollectionAssert.AreEqual(new[] { 24, 78, 31, 28 }, profile.Layers.Select(l => l.ShearStrengthRatioMean)); CollectionAssert.AreEqual(new[] { 0.017499999999999998, 0.011153846153846153, 0.004193548387096774, 0.029285714285714283 }, profile.Layers.Select(l => l.ShearStrengthRatioCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0.04, 0.07, 0.03, 0.08 }, profile.Layers.Select(l => l.ShearStrengthRatioShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.StrengthIncreaseExponentDistributionType)); CollectionAssert.AreEqual(new[] { 1, 3, 4, 2 }, profile.Layers.Select(l => l.StrengthIncreaseExponentMean)); CollectionAssert.AreEqual(new[] { 0.1, 0.09999999999999999, 0.1, 0.1 }, profile.Layers.Select(l => l.StrengthIncreaseExponentCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0.01, 0.03, 0.04, 0.02 }, profile.Layers.Select(l => l.StrengthIncreaseExponentShift)); CollectionAssert.AreEqual(new[] { 3, 3, 3, 3 }, profile.Layers.Select(l => l.PopDistributionType)); CollectionAssert.AreEqual(new[] { 111, 333, 444, 222 }, profile.Layers.Select(l => l.PopMean)); CollectionAssert.AreEqual(new[] { 0.000990990990990991, 0.000990990990990991, 0.000990990990990991, 0.000990990990990991 }, profile.Layers.Select(l => l.PopCoefficientOfVariation)); CollectionAssert.AreEqual(new[] { 0.01, 0.03, 0.04, 0.02 }, profile.Layers.Select(l => l.PopShift)); } Assert.IsTrue(TestHelper.CanOpenFileForWrite(dbFile)); }