Skip to content

Commit

Permalink
add C# and kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
ythirion committed Jan 2, 2024
1 parent 6c89ae9 commit fd666ca
Show file tree
Hide file tree
Showing 496 changed files with 22,271 additions and 0 deletions.
396 changes: 396 additions & 0 deletions exercise/c#/AdventOfCraft.sln

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions exercise/c#/Day01/Day01.Tests/Day01.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Day01\Day01.csproj"/>
</ItemGroup>

</Project>
40 changes: 40 additions & 0 deletions exercise/c#/Day01/Day01.Tests/EdibleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using FluentAssertions;
using Xunit;

namespace Day01.Tests
{
public class EdibleTests
{
private static readonly DateOnly ExpirationDate = new(2023, 12, 1);
private static readonly Guid Inspector = Guid.NewGuid();
private static readonly DateOnly NotFreshDate = ExpirationDate.AddDays(7);
private static readonly DateOnly FreshDate = ExpirationDate.AddDays(-7);

public static IEnumerable<object?[]> NotEdibleFood()
{
return new List<object?[]>
{
new object[] {true, Inspector, NotFreshDate},
new object[] {false, Inspector, FreshDate},
new object?[] {true, null, FreshDate},
new object?[] {false, null, NotFreshDate},
new object?[] {false, null, FreshDate}
};
}

[Theory]
[MemberData(nameof(NotEdibleFood))]
public void Not_Edible_If_Not_Fresh(bool approvedForConsumption, Guid? inspectorId, DateOnly now)
=> new Food(ExpirationDate, approvedForConsumption, inspectorId)
.IsEdible(() => now)
.Should()
.BeFalse();

[Fact]
public void EdibleFood()
=> new Food(ExpirationDate, true, Inspector)
.IsEdible(() => FreshDate)
.Should()
.BeTrue();
}
}
9 changes: 9 additions & 0 deletions exercise/c#/Day01/Day01/Day01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
17 changes: 17 additions & 0 deletions exercise/c#/Day01/Day01/Food.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Day01
{
public record Food(
DateOnly ExpirationDate,
bool ApprovedForConsumption,
Guid? InspectorId)
{
public bool IsEdible(Func<DateOnly> now)
{
if (ExpirationDate.CompareTo(now()) > 0 &&
ApprovedForConsumption &&
InspectorId != null)
return true;
return false;
}
}
}
30 changes: 30 additions & 0 deletions exercise/c#/Day02/Day02.Tests/Day02.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Day02\Day02.csproj"/>
</ItemGroup>

</Project>
85 changes: 85 additions & 0 deletions exercise/c#/Day02/Day02.Tests/FizzBuzzTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using FluentAssertions;
using Xunit;

namespace Day02.Tests
{
public class FizzBuzzTests
{
#region "Normal" numbers

[Fact]
public void Returns_The_Given_Number_For_1() => FizzBuzz.Convert(1).Should().Be("1");

[Fact]
public void Returns_The_Given_Number_For_67() => FizzBuzz.Convert(67).Should().Be("67");

[Fact]
public void Returns_The_Given_Number_For_82() => FizzBuzz.Convert(82).Should().Be("82");

#endregion

#region Fizz

[Fact]
public void Returns_Fizz_For_3() => FizzBuzz.Convert(3).Should().Be("Fizz");

[Fact]
public void Returns_Fizz_For_66() => FizzBuzz.Convert(66).Should().Be("Fizz");

[Fact]
public void Returns_Fizz_For_99() => FizzBuzz.Convert(99).Should().Be("Fizz");

#endregion

#region Buzz

[Fact]
public void Returns_Buzz_For_5() => FizzBuzz.Convert(5).Should().Be("Buzz");

[Fact]
public void Returns_Buzz_For_50() => FizzBuzz.Convert(50).Should().Be("Buzz");

[Fact]
public void Returns_Buzz_For_85() => FizzBuzz.Convert(85).Should().Be("Buzz");

#endregion

#region FizzBuzz

[Fact]
public void Returns_FizzBuzz_For_15() => FizzBuzz.Convert(15).Should().Be("FizzBuzz");

[Fact]
public void Returns_FizzBuzz_For_30() => FizzBuzz.Convert(30).Should().Be("FizzBuzz");

[Fact]
public void Returns_FizzBuzz_For_45() => FizzBuzz.Convert(45).Should().Be("FizzBuzz");

#endregion

#region Failures

[Fact]
public void Throws_An_Exception_For_0()
{
var act = () => FizzBuzz.Convert(0);
act.Should().Throw<OutOfRangeException>();
}

[Fact]
public void Throws_An_Exception_For_101()
{
var act = () => FizzBuzz.Convert(101);
act.Should().Throw<OutOfRangeException>();
}

[Fact]
public void Throws_An_Exception_For_Minus_1()
{
var act = () => FizzBuzz.Convert(-1);
act.Should().Throw<OutOfRangeException>();
}

#endregion
}
}
9 changes: 9 additions & 0 deletions exercise/c#/Day02/Day02/Day02.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
39 changes: 39 additions & 0 deletions exercise/c#/Day02/Day02/FizzBuzz.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Day02
{
public static class FizzBuzz
{
public static string Convert(int input)
{
if (input > 0)
{
if (input <= 100)
{
if (input % 3 == 0 && input % 5 == 0)
{
return "FizzBuzz";
}

if (input % 3 == 0)
{
return "Fizz";
}

if (input % 5 == 0)
{
return "Buzz";
}

return input.ToString();
}
else
{
throw new OutOfRangeException();
}
}
else
{
throw new OutOfRangeException();
}
}
}
}
6 changes: 6 additions & 0 deletions exercise/c#/Day02/Day02/OutOfRangeException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Day02
{
public sealed class OutOfRangeException : ArgumentException
{
}
}
30 changes: 30 additions & 0 deletions exercise/c#/Day03/Day03.Tests/Day03.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Day03\Day03\Day03.csproj"/>
</ItemGroup>

</Project>
30 changes: 30 additions & 0 deletions exercise/c#/Day03/Day03.Tests/PopulationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using FluentAssertions;
using Xunit;
using static Day03.PetType;

namespace Day03.Tests
{
public class PopulationTests
{
private static readonly IEnumerable<Person> Population = new List<Person>
{
new("Peter", "Griffin", new Pet(Cat, "Tabby", 2)),
new("Stewie", "Griffin", new Pet(Cat, "Dolly", 3), new Pet(Dog, "Brian", 9)),
new("Joe", "Swanson", new Pet(Dog, "Spike", 4)),
new("Lois", "Griffin", new Pet(Snake, "Serpy", 1)),
new("Meg", "Griffin", new Pet(Bird, "Tweety", 1)),
new("Chris", "Griffin", new Pet(Turtle, "Speedy", 4)),
new("Cleveland", "Brown", new Pet(Hamster, "Fuzzy", 1), new Pet(Hamster, "Wuzzy", 2)),
new("Glenn", "Quagmire")
};

[Fact]
public void Who_Owns_The_Youngest_Pet()
{
var filtered = Population.MinBy(person => { var youngestPetByAge = person.Pets.MinBy(p => p.Age); return youngestPetByAge?.Age ?? int.MaxValue; });

filtered.Should().NotBeNull();
filtered!.FirstName.Should().Be("Lois");
}
}
}
9 changes: 9 additions & 0 deletions exercise/c#/Day03/Day03/Day03.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
16 changes: 16 additions & 0 deletions exercise/c#/Day03/Day03/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Day03
{
public record Person(string FirstName, string LastName, params Pet[] Pets);

public record Pet(PetType Type, string Name, int Age);

public enum PetType
{
Cat,
Dog,
Hamster,
Turtle,
Bird,
Snake
}
}
Loading

0 comments on commit fd666ca

Please sign in to comment.