/// <summary> /// Метод-обёртка для вычисления НОД чисел a и b. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int CalculateNOD(FindNODType findType, int a, int b) { if (findType == FindNODType.Euclid) { return(a > b?FindNOD(a, b) : FindNOD(b, a)); } else { return(a > b?FindNODByGCD(a, b) : FindNODByGCD(b, a)); } }
/// <summary> /// Метод-обёртка для вычисления НОД чисел a и b. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int CalculateNOD(FindNODType findType, int a, int b) { Func <int, int, int> calc; if (findType == FindNODType.Euclid) { calc = FindNOD; } else { calc = FindNODByGCD; } return(a > b?calc(a, b) : calc(b, a)); }
/// <summary> /// Вычисление НОД у произвольного числа чисел. /// </summary> /// <param name="digits"></param> /// <returns></returns> public static int CalculateNOD(FindNODType findType, params int[] digits) { if (digits.Length < 2) { throw new ArgumentException(); } int iter = CalculateNOD(findType, digits[0], digits[1]); for (int i = 2; i < digits.Length; i++) { iter = CalculateNOD(findType, iter, digits[i]); } return(iter); }
public int FindNODRefactored_Params_Test(FindNODType findType, params int[] digits) { return(NODCalculatesRefactored.CalculateNOD(findType, digits)); }
public void FindNODRefactoredTest_ArgumentOutOfRangeException(FindNODType findType, int a, int b) { Assert.That(() => NODCalculatesRefactored.CalculateNOD(findType, a, b), Throws.Exception.TypeOf <ArgumentOutOfRangeException>()); }
public int FindNODRefactoredTest(FindNODType findType, int a, int b) { return(NODCalculatesRefactored.CalculateNOD(findType, a, b)); }
public int FindNODTest(FindNODType findType, params int[] digits) { return(NODCalculates.CalculateNOD(findType, digits)); }
public int FindNODTest(FindNODType findType, int a, int b) { return(NODCalculates.CalculateNOD(findType, a, b)); }