Beispiel #1
0
        public void CalculateDecorator_With_Params()
        {
            var gcd = new GCD(_algorithm, _stopWatcher, _logger);

            gcd.Calculate(20, 15, 125, 400, -10);
            Mock <IAlgorithm> mockAlgorithm = Mock.Get(_algorithm);

            mockAlgorithm.Verify(a => a.Calculate(It.IsAny <int>(), It.IsAny <int>()), Times.AtLeastOnce);
        }
Beispiel #2
0
 public void Test_Calculate()
 {
     Assert.AreEqual(1, GCD.Calculate(1, 1));
     Assert.AreEqual(1, GCD.Calculate(1, 2));
     Assert.AreEqual(1, GCD.Calculate(37, 39));
     Assert.AreEqual(15, GCD.Calculate(60, 15));
     Assert.AreEqual(3, GCD.Calculate(111, 15));
     Assert.AreEqual(5 * 7 * 13, GCD.Calculate(1 * 3 * 5 * 7 * 11 * 13 * 17, 5 * 7 * 13 * 23));
 }
Beispiel #3
0
        public void CalculateDecorator_With_Two_Parameters_And_StopWatcher_And_Logger()
        {
            var gcd = new GCD(_algorithm, _stopWatcher, _logger);

            gcd.Calculate(1, 3);

            Mock <IAlgorithm> mockAlgorithm = Mock.Get(_algorithm);

            mockAlgorithm.Verify(a => a.Calculate(It.IsAny <int>(), It.IsAny <int>()), Times.Once);

            Mock <ILogger> mockLogger = Mock.Get(_logger);

            mockLogger.Verify(l => l.Info(It.IsAny <string>()), Times.AtLeastOnce);

            Mock <IStopWatcher> mockStopWatcher = Mock.Get(_stopWatcher);

            mockStopWatcher.Verify(sw => sw.Start());
            mockStopWatcher.Verify(sw => sw.Stop());
        }
 public void ThrowIfNull()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => GCD.Calculate(0, 0));
 }
        public void GCDCorrect(int a, int b, int correct)
        {
            var result = GCD.Calculate(a, b);

            Assert.Equal(correct, result);
        }
Beispiel #6
0
        public static void FindGcdByStein_ZeroParams_ArgumentExeption()
        {
            var gcd = new GCD(new EuclideanAlgorithm(), new StopWatcher(), new Logger());

            Assert.Throws <ArgumentException>(() => gcd.Calculate(0, 0, 0, 0, 0, 0, 0));
        }
Beispiel #7
0
        public static int FindGcdByEuclidean_Params_GCD(params int[] numbers)
        {
            var gcd = new GCD(new EuclideanAlgorithm(), new StopWatcher(), new Logger());

            return(gcd.Calculate(numbers));
        }
Beispiel #8
0
        public static void FindGcdByEuclidian_IntMinValue_ArgumentExeption()
        {
            var gcd = new GCD(new EuclideanAlgorithm(), new StopWatcher(), new Logger());

            Assert.Throws <ArgumentException>(() => gcd.Calculate(int.MaxValue, int.MinValue));
        }