Skip to content

Instantly share code, notes, and snippets.

View alefcarlos's full-sized avatar
✌️
Focusing

Alef Carlos alefcarlos

✌️
Focusing
View GitHub Profile
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>
@alefcarlos
alefcarlos / HelpersTest.cs
Created January 7, 2019 21:15
Using [Fact] attribute with xUnit
using Shouldly;
using Xunit;
namespace Problems.Tests
{
public class HelpersTess
{
[Fact]
public void Sum_ShouldBeSuccess()
{
@alefcarlos
alefcarlos / HelpersTest.cs
Created January 7, 2019 21:26
Test without Shouldly
using Xunit;
namespace Problems.Tests
{
public class HelpersTess
{
[Fact]
public void Sum_ShouldBeSuccess()
{
// Helpers.Sum(1, 2).ShouldBe(3);
using Shouldly;
using Xunit;
namespace Problems.Tests
{
public class HelpersTess
{
[Fact]
public void Sum_ShouldBeSuccess()
{
/// <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)
[Fact]
public void MultpleOf_ShouldThrowExpcetion()
{
Should.Throw<ArgumentException>(() =>
{
Helpers.IsMultipleOf(0, 3);
});
}
[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();
[Theory]
[InlineData(3, 1)]
[InlineData(3, 5)]
public void Multiple_ShouldFail(int y, int x)
{
Helpers.IsMultipleOf(y, x).ShouldBeFalse();
}
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++)
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.