public void Agcd_ShouldReturnCorrectAgcd(decimal a, decimal b, decimal expectedAgcd)
        {
            // Arrange
            const decimal gcdTolerancePercent = 0m;

            // Act
            var agcd = ApproximateGcdCalculator.Agcd(gcdTolerancePercent, a, b);

            // Assert
            agcd.Should().BeApproximately(expectedAgcd, FloatingPointTolerance);
        }
        public void Agcd_ShouldReturnAgcdWithinTolerance(decimal a, decimal b, decimal expectedAgcd,
                                                         decimal allowedGcdTolerancePercent)
        {
            // Arrange

            // Act
            var agcd = ApproximateGcdCalculator.Agcd(allowedGcdTolerancePercent, a, b);

            // Assert
            agcd.Should().BeApproximately(expectedAgcd, FloatingPointTolerance);
        }
        public void Agcd_ShouldReturnAgcdWithinTolerance(decimal allowedGcdTolerancePercent,
                                                         decimal expectedAgcd, params double[] arguments)
        {
            // Arrange
            var args = arguments.Select(d => (decimal)d).ToArray();

            // Act
            var agcd = ApproximateGcdCalculator.Agcd(allowedGcdTolerancePercent, args);

            // Assert
            agcd.Should().BeApproximately(expectedAgcd, FloatingPointTolerance);
        }
        // TODO[mk] generate random data
        public void Agcd_ShouldReturnValueWhichDivideWithAllowedRemainder(decimal a, decimal b,
                                                                          decimal allowedGcdTolerancePercent)
        {
            // Arrange

            // Act
            var agcd = ApproximateGcdCalculator.Agcd(allowedGcdTolerancePercent, a, b);

            // Assert
            var allowedRemainderA = a * allowedGcdTolerancePercent / 100m;
            var allowedRemainderB = b * allowedGcdTolerancePercent / 100m;
            var remainderA        = a % agcd;
            var remainderB        = b % agcd;

            remainderA.Should().BeLessOrEqualTo(allowedRemainderA);
            remainderB.Should().BeLessOrEqualTo(allowedRemainderB);
        }
Пример #5
0
 /// <summary>
 /// Calculates Approximate Greatest Common Divisor (AGCD)
 /// of two non-negative real numbers with specified tolerance.
 /// </summary>
 /// <param name="tolerancePercent">Allowed tolerance to find AGCD.</param>
 public static decimal Agcd(decimal tolerancePercent, decimal a, decimal b) =>
 ApproximateGcdCalculator.Agcd(tolerancePercent, a, b);