private static int CalculateGcdOfThreeValues(CalculateGcd calculateMethod, int a, int b, int c) { int temporyGCD = calculateMethod(a, b); temporyGCD = calculateMethod(c, temporyGCD); return(temporyGCD); }
private static int CalculateGcdOfValues(CalculateGcd calculateMethod, params int[] values) { if (values == null) { throw new ArgumentNullException(); } if (values.Count() == 0) { throw new ArgumentNullException(); } if (values.Count() == 1) { return(values[0]); } int temporyGCD = values[0]; for (int i = 1; i < values.Count(); i++) { temporyGCD = calculateMethod(values[i], temporyGCD); if (temporyGCD == 1) { return(1); } } return(temporyGCD); }
public static int GcdByMethod(out long ticks, CalculateGcd method, params int[] values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (values.Length == 1) { throw new ArgumentException("Enter more than one argument " + nameof(values)); } var watch = new Stopwatch(); watch.Start(); var result = method(values[0], values[1]); for (int i = 2; i < values.Length; i++) { result = method(values[i], result); } watch.Stop(); ticks = watch.ElapsedTicks; return(Math.Abs(result)); }
public void calculateGcd_should_throw_exception_for_boundary_values() { //arrange CalculateGcd calculate = new CalculateGcd(); int a = 0; int b = 0; //act //assert Assert.ThrowsException <System.ArgumentException>(() => calculate.GetGcd(a, b)); }
public void calculateGcd_should_return_correct_value_when_second_value_higher() { //arrange CalculateGcd calculate = new CalculateGcd(); int a = 12; int b = 36; float expected = 12; //act float actual = calculate.GetGcd(a, b); //assert Assert.AreEqual(expected, actual, "is not equal"); }
public static int GcdByMethod(out long ticks, CalculateGcd method, params int[] values) { if (values == null) throw new ArgumentNullException(nameof(values)); if (values.Count() == 1) throw new ArgumentException("Enter more than one argument " + nameof(values)); var watch = new Stopwatch(); watch.Start(); var result = method(values[0], values[1]); for (int i = 2; i < values.Length; i++) result = method(values[i], result); watch.Stop(); ticks = watch.ElapsedTicks; return Math.Abs(result); }
private static int CalculateGcdOfThreeValues(CalculateGcd calculateMethod, int a, int b, int c) { int temporyGCD = calculateMethod(a, b); temporyGCD = calculateMethod(c, temporyGCD); return temporyGCD; }
private static int CalculateGcdOfValues(CalculateGcd calculateMethod, params int[] values) { if (values == null) { throw new ArgumentNullException(); } if (values.Count() == 0) { throw new ArgumentNullException(); } if (values.Count() == 1) { return values[0]; } int temporyGCD = values[0]; for (int i = 1; i < values.Count(); i++) { temporyGCD = calculateMethod(values[i], temporyGCD); if (temporyGCD == 1) return 1; } return temporyGCD; }