Beispiel #1
0
        public void Gcd_ShouldReturnCorrectGcd(int expectedGcd, params int[] arguments)
        {
            // Arrange

            // Act
            var gcd = IntegerGcdCalculator.Gcd(arguments);

            // Assert
            gcd.Should().Be(expectedGcd);
        }
Beispiel #2
0
        public void Gcd_ShouldReturnCorrectGcd(int a, int b, int expectedGcd)
        {
            // Arrange

            // Act
            var gcd = IntegerGcdCalculator.Gcd(a, b);

            // Assert
            gcd.Should().Be(expectedGcd);
        }
Beispiel #3
0
        public void Gcd_IfAnyArgumentIsNegative_ShouldThrowArgumentException(int a, int b)
        {
            // Arrange

            // Act
            Action action = () => _ = IntegerGcdCalculator.Gcd(a, b);

            // Assert
            action.Should().Throw <ArgumentException>();
        }
Beispiel #4
0
        // TODO[mk] add random data generation + output logging
        public void Gcd_ShouldBeCommutative(int a, int b)
        {
            // Arrange

            // Act
            var gcdDirect  = IntegerGcdCalculator.Gcd(a, b);
            var gcdInverse = IntegerGcdCalculator.Gcd(b, a);

            // Assert
            gcdDirect.Should().Be(gcdInverse);
        }
Beispiel #5
0
        // TODO[mk] add random data generation + output logging
        public void Gcd_ShouldReturnValueWhichDivideToCoprimeQuotients(int a, int b)
        {
            // Arrange

            // Act
            var gcd = IntegerGcdCalculator.Gcd(a, b);

            // Assert
            var quotientA    = a / gcd;
            var quotientB    = b / gcd;
            var quotientsGcd = IntegerGcdCalculator.Gcd(quotientA, quotientB);

            quotientsGcd.Should().Be(1);
        }
Beispiel #6
0
        // TODO[mk] add random data generation + output logging
        public void Gcd_ShouldReturnValueWhichDivideWithoutRemainder(int a, int b)
        {
            // Arrange

            // Act
            var gcd = IntegerGcdCalculator.Gcd(a, b);

            // Assert
            var remainderA = a % gcd;
            var remainderB = b % gcd;

            remainderA.Should().Be(0);
            remainderB.Should().Be(0);
        }
Beispiel #7
0
 /// <summary>
 /// Calculates Greatest Common Divisor (GCD)
 /// of arbitrary number of non-negative integer numbers.
 /// </summary>
 /// <exception cref="ArgumentException"></exception>
 public static int Gcd(params int[] arguments) =>
 IntegerGcdCalculator.Gcd(arguments);
Beispiel #8
0
 /// <summary>
 /// Calculates Greatest Common Divisor (GCD)
 /// of two non-negative integer numbers.
 /// </summary>
 /// <exception cref="ArgumentException"></exception>
 public static int Gcd(int a, int b) =>
 IntegerGcdCalculator.Gcd(a, b);