public void IsMultipleOfFive_WhenGivenNonMultipleOfFive_ShouldReturnFalse() { const Int32 value = 6; Boolean actual = IntegerHelper.IsMultipleOfFive(value); Assert.That(actual, Is.False); }
public void IsMultipleOfThree_WhenGivenAMultipleOfThree_ShouldReturnTrue() { const Int32 value = 6; Boolean actual = IntegerHelper.IsMultipleOfThree(value); Assert.That(actual, Is.True); }
public void SumRange_ShouldSumGivenRange() { const Int32 initial = 1; const Int32 maximum = 10; const Int32 expected = 45; // Int32[] values = {1, 2, 3, 4, 5, 6, 7, 8, 9}; Int32 actual = IntegerHelper.SumRange(initial, maximum); Assert.That(actual, Is.EqualTo(expected)); }
public void GetRange_WhenGivenAMinimumAndMaximumValue_ShouldReturnRangeOfIntegersBetweenValues() { const Int32 initial = 1; const Int32 maximum = 10; Int32[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; Int32[] actual = IntegerHelper.GetRange(initial, maximum).ToArray(); Assert.That(actual, Is.Not.Empty); Assert.That(actual, Is.EqualTo(values)); }
public void SumRange_WithGivenConditions_ShouldReturnSumOfRange() { const Int32 initial = 1; const Int32 maximum = 10; const Int32 expected = 23; //Int32[] values = { 3, 5, 6, 9 }; Func <Int32, Boolean>[] conditions = { IntegerHelper.IsMultipleOfThree, IntegerHelper.IsMultipleOfFive }; Int32 actual = IntegerHelper.SumRange(initial, maximum, conditions); Assert.That(actual, Is.EqualTo(expected)); }
public void GetRange_WhenGivenStartAndMaximumValueWithConditions_ShouldReturnRangeOfIntegersMatchingThoseConditions() { const Int32 initial = 1; const Int32 maximum = 10; Int32[] values = { 3, 5, 6, 9 }; Func <Int32, Boolean>[] conditions = { IntegerHelper.IsMultipleOfThree, IntegerHelper.IsMultipleOfFive }; Int32[] actual = IntegerHelper.GetRange(initial, maximum, conditions).ToArray(); Assert.That(actual, Is.Not.Empty); Assert.That(actual, Is.EqualTo(values)); }
public static void Main(string[] args) { Console.Title = "Problem One: Sum all multiples of 3 and 5 below 1000."; /* * Problem One: * * If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. * Find the sum of all the multiples of 3 or 5 below 1000. */ Func <Int32, Boolean>[] conditions = { x => (x % 3) == 0, x => (x % 5) == 0 }; Stopwatch watch; Boolean exit = false; do { Console.Write("Enter a starting value: "); String value = Console.ReadLine(); Int32 startingValue; if (!Int32.TryParse(value, out startingValue)) { Console.WriteLine("Bad argument given."); Console.ReadKey(true); return; } Console.Write("Enter a final value: "); value = Console.ReadLine(); Int32 finalValue; if (!Int32.TryParse(value, out finalValue)) { Console.WriteLine("Bad argument given."); Console.ReadKey(true); return; } watch = Stopwatch.StartNew(); Console.WriteLine("Calculating sum..."); Int32 sum = IntegerHelper.SumRange(startingValue, finalValue, conditions); watch.Stop(); Console.WriteLine("Completed in {0:##.000}ms. Sum from {1} to {2} is {3}", watch.ElapsedMilliseconds, startingValue, finalValue, sum); Console.Write("Would you like to try again? [y/n] [default: y] "); value = Console.ReadLine(); if (value != null && value.Equals("n", StringComparison.OrdinalIgnoreCase)) { exit = true; } Console.Clear(); } while (!exit); }