SonarLint.VisualStudio.Progress.Observation.ViewModels.ProgressViewModel.SetUpperBoundLimitedValue C# (CSharp) Метод

SetUpperBoundLimitedValue() публичный Метод

Will set the value whilst taking into account potential floating point errors when incrementing the value in a way that the sum is greater than 1.0 (within UpperBoundMarginalErrorSupport). Double.NaN values are also supported by this method (pass-through).
public SetUpperBoundLimitedValue ( double value ) : void
value double
Результат void
        public void SetUpperBoundLimitedValue(double value)
        {
            if (double.IsInfinity(value) || value < 0.0 || value > 1.0 + UpperBoundMarginalErrorSupport)
            {
                throw new ArgumentOutOfRangeException(nameof(value), value, string.Empty);
            }

            this.Value = Math.Min(1.0, value); // min should return NaN if value is NaN
        }
    }

Usage Example

        public void ProgressViewModel_SetUpperBoundLimitedValue()
        {
            // Setup
            ProgressViewModel testSubject = new ProgressViewModel();

            // Sanity
            Assert.AreEqual(0, testSubject.Value, "Default value expected");

            // Act + Verify

            // Erroneous cases
            Exceptions.Expect<ArgumentOutOfRangeException>(() => testSubject.SetUpperBoundLimitedValue(double.NegativeInfinity));
            Exceptions.Expect<ArgumentOutOfRangeException>(() => testSubject.SetUpperBoundLimitedValue(double.PositiveInfinity));
            Exceptions.Expect<ArgumentOutOfRangeException>(() => testSubject.SetUpperBoundLimitedValue(0 - double.Epsilon));
            Exceptions.Expect<ArgumentOutOfRangeException>(() => testSubject.SetUpperBoundLimitedValue(1.0 + ProgressViewModel.UpperBoundMarginalErrorSupport + ProgressViewModel.UpperBoundMarginalErrorSupport));

            // Sanity
            Assert.AreEqual(0.0, testSubject.Value, "Erroneous cases should not change the default value");

            // NaN supported
            testSubject.SetUpperBoundLimitedValue(double.NaN);
            Assert.AreEqual(double.NaN, testSubject.Value);

            // Zero in range
            testSubject.SetUpperBoundLimitedValue(0);
            Assert.AreEqual(0.0, testSubject.Value);

            // One is in range
            testSubject.SetUpperBoundLimitedValue(1);
            Assert.AreEqual(1.0, testSubject.Value);

            // Anything between zero and one is in range
            Random r = new Random();
            double val = r.NextDouble();
            testSubject.SetUpperBoundLimitedValue(val);
            Assert.AreEqual(val, testSubject.Value);

            // More than one (i.e floating point summation errors) will become one
            testSubject.SetUpperBoundLimitedValue(1.0 + ProgressViewModel.UpperBoundMarginalErrorSupport);
            Assert.AreEqual(1.0, testSubject.Value);
        }
ProgressViewModel