public void GetAmicableNumber_Throws_Exception_When_Input_Number_Is_Not_Part_Of_Amicable_Pair() { var inputNumber = 13; Action getAmicableNumber = () => GeneralHelpers.GetAmicableNumber(13); getAmicableNumber.Should().Throw <NotPartOfAmicablePairException>() .WithMessage($"{inputNumber} is not part of an amicable pair."); }
/// <summary> /// Run solution for problem 21. /// </summary> /// <param name="rangeThreshold">Range threshold.</param> /// <returns>Sum of amicable numbers below <paramref name="rangeThreshold"/>.</returns> public static int Run(int rangeThreshold) { var amicableNumbersSum = 0; for (var i = 3; i < rangeThreshold; i += 1) { try { var amicableNumber = GeneralHelpers.GetAmicableNumber(i); if (amicableNumber != 0) { amicableNumbersSum += i + amicableNumber; i = amicableNumber; } } catch (NotPartOfAmicablePairException) { } } return(amicableNumbersSum); }
public void GetAmicableNumber_Returns_Input_Numbers_Amicable_Number() { GeneralHelpers.GetAmicableNumber(220).Should().Be(284); }