This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Problems | |
{ | |
public static class Helpers | |
{ | |
/// <summary> | |
/// Sums two numbers. | |
/// </summary> | |
/// <param name="a">First number.</param> | |
/// <param name="b">Second number.</param> | |
/// <returns>Returns the sum of two specified integer numbers.</returns> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Shouldly; | |
using Xunit; | |
namespace Problems.Tests | |
{ | |
public class HelpersTess | |
{ | |
[Fact] | |
public void Sum_ShouldBeSuccess() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Xunit; | |
namespace Problems.Tests | |
{ | |
public class HelpersTess | |
{ | |
[Fact] | |
public void Sum_ShouldBeSuccess() | |
{ | |
// Helpers.Sum(1, 2).ShouldBe(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Shouldly; | |
using Xunit; | |
namespace Problems.Tests | |
{ | |
public class HelpersTess | |
{ | |
[Fact] | |
public void Sum_ShouldBeSuccess() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Validadtes if a value is multiple of other number | |
/// </summary> | |
/// <param name="y">The desired multiple.</param> | |
/// <param name="x">Value to check.</param> | |
/// <returns>Returns true if value is multiple of multiple</returns> | |
public static bool IsMultipleOf(int y, int x) | |
{ | |
//Check possible DivisionByZero | |
if (y == 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void MultpleOf_ShouldThrowExpcetion() | |
{ | |
Should.Throw<ArgumentException>(() => | |
{ | |
Helpers.IsMultipleOf(0, 3); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Theory] | |
[InlineData(3, 3)] | |
[InlineData(3, 6)] | |
[InlineData(3, 9)] | |
[InlineData(5, 5)] | |
[InlineData(5, 10)] | |
[InlineData(5, 15)] | |
public void Multiple_ShouldSuccess(int y, int x) | |
{ | |
Helpers.IsMultipleOf(y, x).ShouldBeTrue(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Theory] | |
[InlineData(3, 1)] | |
[InlineData(3, 5)] | |
public void Multiple_ShouldFail(int y, int x) | |
{ | |
Helpers.IsMultipleOf(y, x).ShouldBeFalse(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
.... | |
public static int SumOfMultiples(int max, params int[] possibleMultiples) | |
{ | |
int sum = 0; | |
//Validate if the number is MultipleOf, then sum it | |
for (int value = 1; value < max; value++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Shouldly; | |
using Xunit; | |
namespace Problems.Tests | |
{ | |
public class ProblemsSolutionTests | |
{ | |
/// <summary> | |
/// 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. |
OlderNewer