Пример #1
0
        public void Constructor_ValidArguments_ReturnExpectedValues()
        {
            // Setup
            const string name = "Stochast name";
            const string unit = "-";

            var    random      = new Random(21);
            double duration    = random.NextDouble();
            double alpha       = random.NextDouble();
            double realization = random.NextDouble();

            // Call
            var stochast = new SubMechanismIllustrationPointStochast(name, unit, duration, alpha, realization);

            // Assert
            Assert.IsInstanceOf <Stochast>(stochast);
            Assert.AreEqual(name, stochast.Name);
            Assert.AreEqual(unit, stochast.Unit);
            Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());

            Assert.AreEqual(realization, stochast.Realization,
                            stochast.Realization.GetAccuracy());
            Assert.AreEqual(5, stochast.Realization.NumberOfDecimalPlaces);
        }
Пример #2
0
        public void Convert_ValidArguments_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);
            var hydraRingWindDirection = new HydraRingWindDirection("Name", random.NextDouble());

            var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(hydraRingWindDirection,
                                                                                                    "closing scenario");

            var hydraRingIllustrationPointResult = new HydraRingIllustrationPointResult("HydraIllustrationPointResult",
                                                                                        "-",
                                                                                        random.NextDouble());

            var hydraRingSubMechanismIllustrationPointStochast =
                new HydraRingSubMechanismIllustrationPointStochast("HydraSubMechanismIllustrationPointStochast",
                                                                   "-",
                                                                   random.NextDouble(),
                                                                   random.NextDouble(),
                                                                   random.NextDouble());

            var hydraRingSubMechanismIllustrationPoint = new HydraRingSubMechanismIllustrationPoint("name", new[]
            {
                hydraRingSubMechanismIllustrationPointStochast
            }, new[]
            {
                hydraRingIllustrationPointResult
            }, random.NextDouble());

            // Call
            TopLevelSubMechanismIllustrationPoint combination =
                TopLevelSubMechanismIllustrationPointConverter.Convert(
                    hydraRingWindDirectionClosingSituation, hydraRingSubMechanismIllustrationPoint);

            // Assert
            WindDirection windDirection = combination.WindDirection;

            Assert.AreEqual(hydraRingWindDirection.Angle, windDirection.Angle, windDirection.Angle.GetAccuracy());
            Assert.AreEqual(hydraRingWindDirection.Name, windDirection.Name);

            Assert.AreEqual(hydraRingWindDirectionClosingSituation.ClosingSituation, combination.ClosingSituation);

            SubMechanismIllustrationPoint subMechanismIllustrationPoint = combination.SubMechanismIllustrationPoint;

            Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Name, subMechanismIllustrationPoint.Name);

            IllustrationPointResult illustrationPointResult = subMechanismIllustrationPoint.IllustrationPointResults.Single();

            Assert.AreEqual(hydraRingIllustrationPointResult.Description, illustrationPointResult.Description);
            Assert.AreEqual(hydraRingIllustrationPointResult.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy());

            SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single();

            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Unit, stochast.Unit);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
        }
Пример #3
0
 private static void AssertReadStochast(SubMechanismIllustrationPointStochastEntity stochastEntity,
                                        SubMechanismIllustrationPointStochast readStochast)
 {
     Assert.AreEqual(stochastEntity.Name, readStochast.Name);
     Assert.AreEqual(stochastEntity.Unit, readStochast.Unit);
     Assert.AreEqual(stochastEntity.Alpha, readStochast.Alpha, readStochast.Alpha.GetAccuracy());
     Assert.AreEqual(stochastEntity.Duration, readStochast.Duration, readStochast.Duration.GetAccuracy());
     Assert.AreEqual(stochastEntity.Realization, readStochast.Realization, readStochast.Realization.GetAccuracy());
 }
        public void Create_ValidIllustrationPointWithStochasts_ReturnSubMechanismIllustrationPointEntityWithStochastEntities()
        {
            // Setup
            var random      = new Random(21);
            var stochastOne = new SubMechanismIllustrationPointStochast("stochast name",
                                                                        "-",
                                                                        random.NextDouble(),
                                                                        random.NextDouble(),
                                                                        random.NextDouble());
            var stochastTwo = new SubMechanismIllustrationPointStochast("Stochast name two",
                                                                        "-",
                                                                        random.NextDouble(),
                                                                        random.NextDouble(),
                                                                        random.NextDouble());

            SubMechanismIllustrationPointStochast[] stochasts =
            {
                stochastOne,
                stochastTwo
            };

            var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name",
                                                                      random.NextDouble(),
                                                                      stochasts,
                                                                      Enumerable.Empty <IllustrationPointResult>());
            int order = random.Next();

            // Call
            SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order);

            // Assert
            AssertCommonProperties(illustrationPoint, entity);
            Assert.AreEqual(order, entity.Order);
            SubMechanismIllustrationPointStochastEntity[] stochastEntities =
                entity.SubMechanismIllustrationPointStochastEntities.ToArray();
            int expectedNrOfStochasts = stochasts.Length;

            Assert.AreEqual(expectedNrOfStochasts, stochastEntities.Length);
            for (var i = 0; i < expectedNrOfStochasts; i++)
            {
                SubMechanismIllustrationPointStochast       stochast       = stochasts[i];
                SubMechanismIllustrationPointStochastEntity stochastEntity = stochastEntities[i];

                TestHelper.AssertAreEqualButNotSame(stochast.Name, stochastEntity.Name);
                TestHelper.AssertAreEqualButNotSame(stochast.Unit, stochastEntity.Unit);
                Assert.AreEqual(stochast.Duration, stochastEntity.Duration, stochast.Duration.GetAccuracy());
                Assert.AreEqual(stochast.Alpha, stochastEntity.Alpha, stochast.Alpha.GetAccuracy());
                Assert.AreEqual(stochast.Realization, stochastEntity.Realization, stochast.Realization.GetAccuracy());
                Assert.AreEqual(i, stochastEntity.Order);
            }
        }
Пример #5
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var random   = new Random(21);
            var original = new SubMechanismIllustrationPointStochast("Random name",
                                                                     "-",
                                                                     random.NextDouble(),
                                                                     random.NextDouble(),
                                                                     random.NextDouble());

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
Пример #6
0
        private static void AssertStochasts(SubMechanismIllustrationPointStochastEntity[] stochastEntities,
                                            SubMechanismIllustrationPointStochast[] stochasts)
        {
            Assert.AreEqual(stochastEntities.Length, stochasts.Length);

            for (var i = 0; i < stochastEntities.Length; i++)
            {
                SubMechanismIllustrationPointStochastEntity stochastEntity = stochastEntities[i];
                SubMechanismIllustrationPointStochast       stochast       = stochasts[i];

                Assert.AreEqual(stochastEntity.Name, stochast.Name);
                Assert.AreEqual(stochastEntity.Unit, stochast.Unit);
                Assert.AreEqual(stochastEntity.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
                Assert.AreEqual(stochastEntity.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
                Assert.AreEqual(stochastEntity.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
            }
        }
Пример #7
0
        public void Convert_ValidArguments_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);
            var hydraIllustrationPointResult = new HydraRingIllustrationPointResult("HydraIllustrationPointResult",
                                                                                    "-",
                                                                                    random.NextDouble());

            const string name        = "hydraRingSubMechanismIllustrationPointStochast";
            const string unit        = "-";
            double       alpha       = random.NextDouble();
            double       duration    = random.NextDouble();
            double       realization = random.NextDouble();
            var          hydraRingSubMechanismIllustrationPointStochast =
                new HydraRingSubMechanismIllustrationPointStochast(name, unit, duration, alpha, realization);

            double beta = random.NextDouble();
            var    hydraSubMechanismIllustrationPoint = new HydraRingSubMechanismIllustrationPoint("name", new[]
            {
                hydraRingSubMechanismIllustrationPointStochast
            }, new[]
            {
                hydraIllustrationPointResult
            }, beta);

            // Call
            SubMechanismIllustrationPoint subMechanismIllustrationPoint =
                SubMechanismIllustrationPointConverter.Convert(hydraSubMechanismIllustrationPoint);

            // Assert
            Assert.AreEqual(subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(subMechanismIllustrationPoint.Name, subMechanismIllustrationPoint.Name);

            IllustrationPointResult illustrationPointResult = subMechanismIllustrationPoint.IllustrationPointResults.Single();

            Assert.AreEqual(hydraIllustrationPointResult.Description, illustrationPointResult.Description);
            Assert.AreEqual(hydraIllustrationPointResult.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy());

            SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single();

            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Unit, stochast.Unit);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
        }
        /// <summary>
        /// Creates a <see cref="SubMechanismIllustrationPointStochastEntity"/> based on the information
        /// of the <paramref name="subMechanismIllustrationPointStochast"/>.
        /// </summary>
        /// <param name="subMechanismIllustrationPointStochast">The stochast to create a database entity for.</param>
        /// <param name="order">The index at which <paramref name="subMechanismIllustrationPointStochast"/> resides within its parent.</param>
        /// <returns>A new <see cref="SubMechanismIllustrationPointStochastEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="subMechanismIllustrationPointStochast"/>
        /// is <c>null</c>.</exception>
        internal static SubMechanismIllustrationPointStochastEntity Create(
            this SubMechanismIllustrationPointStochast subMechanismIllustrationPointStochast, int order)
        {
            if (subMechanismIllustrationPointStochast == null)
            {
                throw new ArgumentNullException(nameof(subMechanismIllustrationPointStochast));
            }

            var entity = new SubMechanismIllustrationPointStochastEntity
            {
                Name        = subMechanismIllustrationPointStochast.Name.DeepClone(),
                Unit        = subMechanismIllustrationPointStochast.Unit.DeepClone(),
                Alpha       = subMechanismIllustrationPointStochast.Alpha,
                Duration    = subMechanismIllustrationPointStochast.Duration,
                Realization = subMechanismIllustrationPointStochast.Realization,
                Order       = order
            };

            return(entity);
        }
Пример #9
0
        public void Constructor_WithParameters_ReturnsNewInstance()
        {
            // Setup
            const string name = "stochast name";
            const string unit = "-";

            var    random      = new Random(21);
            double duration    = random.NextDouble();
            double alpha       = random.NextDouble();
            double realization = random.NextDouble();

            // Call
            var stochast = new SubMechanismIllustrationPointStochast(name, unit, duration, alpha, realization);

            // Assert
            Assert.IsInstanceOf <Stochast>(stochast);
            Assert.AreEqual(name, stochast.Name);
            Assert.AreEqual(unit, stochast.Unit);
            Assert.AreEqual(duration, stochast.Duration);
            Assert.AreEqual(alpha, stochast.Alpha);
            Assert.AreEqual(realization, stochast.Realization);
        }
        public void Create_ValidStochast_ReturnSubMechanismIllustrationPointStochastEntity()
        {
            // Setup
            var random   = new Random(123);
            var stochast = new SubMechanismIllustrationPointStochast("Some description",
                                                                     "-",
                                                                     random.NextDouble(),
                                                                     random.NextDouble(),
                                                                     random.NextDouble());
            int order = random.Next();

            // Call
            SubMechanismIllustrationPointStochastEntity entity = stochast.Create(order);

            // Assert
            TestHelper.AssertAreEqualButNotSame(stochast.Name, entity.Name);
            TestHelper.AssertAreEqualButNotSame(stochast.Unit, entity.Unit);
            Assert.AreEqual(stochast.Alpha, entity.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(stochast.Duration, entity.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(stochast.Realization, entity.Realization, stochast.Realization.GetAccuracy());
            Assert.AreEqual(order, entity.Order);
        }
Пример #11
0
        public void Convert_ValidHydraRingSubMechanismIllustrationPointStochast_ExpectedProperties()
        {
            // Setup
            const string name = "name";
            const string unit = "-";

            var    random      = new Random(21);
            double duration    = random.Next();
            double alpha       = random.NextDouble();
            double realization = random.NextDouble();

            var hydraRingStochast = new HydraRingSubMechanismIllustrationPointStochast(name, unit, duration, alpha, realization);

            // Call
            SubMechanismIllustrationPointStochast stochast = StochastConverter.Convert(hydraRingStochast);

            // Assert
            Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingStochast.Unit, stochast.Unit);
            Assert.AreEqual(hydraRingStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
        }
        public void Read_ValidEntity_ReturnRealizedStochast()
        {
            // Setup
            var random = new Random(123);
            var entity = new SubMechanismIllustrationPointStochastEntity
            {
                Name        = "Description",
                Unit        = "-",
                Alpha       = random.NextDouble(),
                Duration    = random.NextDouble(),
                Realization = random.NextDouble()
            };

            // Call
            SubMechanismIllustrationPointStochast illustrationPointResult = entity.Read();

            // Assert
            Assert.AreEqual(entity.Name, illustrationPointResult.Name);
            Assert.AreEqual(entity.Unit, illustrationPointResult.Unit);
            Assert.AreEqual(entity.Alpha, illustrationPointResult.Alpha, illustrationPointResult.Alpha.GetAccuracy());
            Assert.AreEqual(entity.Duration, illustrationPointResult.Duration, illustrationPointResult.Duration.GetAccuracy());
            Assert.AreEqual(entity.Realization, illustrationPointResult.Realization, illustrationPointResult.Realization.GetAccuracy());
        }
Пример #13
0
 /// <summary>
 /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/>
 /// are clones.
 /// </summary>
 /// <param name="original">The original object.</param>
 /// <param name="clone">The cloned object.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and
 /// <paramref name="clone"/> are not clones.</exception>
 public static void AreClones(SubMechanismIllustrationPointStochast original, SubMechanismIllustrationPointStochast clone)
 {
     AreClones((Stochast)original, clone);
     Assert.AreEqual(original.Unit, clone.Unit);
     Assert.AreEqual(original.Realization, clone.Realization);
 }