Skip to content

Commit fd666ca

Browse files
committed
add C# and kotlin
1 parent 6c89ae9 commit fd666ca

File tree

496 files changed

+22271
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

496 files changed

+22271
-0
lines changed

exercise/c#/AdventOfCraft.sln

Lines changed: 396 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="xunit" Version="2.6.4" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.0">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\Day01\Day01.csproj"/>
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace Day01.Tests
5+
{
6+
public class EdibleTests
7+
{
8+
private static readonly DateOnly ExpirationDate = new(2023, 12, 1);
9+
private static readonly Guid Inspector = Guid.NewGuid();
10+
private static readonly DateOnly NotFreshDate = ExpirationDate.AddDays(7);
11+
private static readonly DateOnly FreshDate = ExpirationDate.AddDays(-7);
12+
13+
public static IEnumerable<object?[]> NotEdibleFood()
14+
{
15+
return new List<object?[]>
16+
{
17+
new object[] {true, Inspector, NotFreshDate},
18+
new object[] {false, Inspector, FreshDate},
19+
new object?[] {true, null, FreshDate},
20+
new object?[] {false, null, NotFreshDate},
21+
new object?[] {false, null, FreshDate}
22+
};
23+
}
24+
25+
[Theory]
26+
[MemberData(nameof(NotEdibleFood))]
27+
public void Not_Edible_If_Not_Fresh(bool approvedForConsumption, Guid? inspectorId, DateOnly now)
28+
=> new Food(ExpirationDate, approvedForConsumption, inspectorId)
29+
.IsEdible(() => now)
30+
.Should()
31+
.BeFalse();
32+
33+
[Fact]
34+
public void EdibleFood()
35+
=> new Food(ExpirationDate, true, Inspector)
36+
.IsEdible(() => FreshDate)
37+
.Should()
38+
.BeTrue();
39+
}
40+
}

exercise/c#/Day01/Day01/Day01.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

exercise/c#/Day01/Day01/Food.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Day01
2+
{
3+
public record Food(
4+
DateOnly ExpirationDate,
5+
bool ApprovedForConsumption,
6+
Guid? InspectorId)
7+
{
8+
public bool IsEdible(Func<DateOnly> now)
9+
{
10+
if (ExpirationDate.CompareTo(now()) > 0 &&
11+
ApprovedForConsumption &&
12+
InspectorId != null)
13+
return true;
14+
return false;
15+
}
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="xunit" Version="2.6.4" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.0">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\Day02\Day02.csproj"/>
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
4+
namespace Day02.Tests
5+
{
6+
public class FizzBuzzTests
7+
{
8+
#region "Normal" numbers
9+
10+
[Fact]
11+
public void Returns_The_Given_Number_For_1() => FizzBuzz.Convert(1).Should().Be("1");
12+
13+
[Fact]
14+
public void Returns_The_Given_Number_For_67() => FizzBuzz.Convert(67).Should().Be("67");
15+
16+
[Fact]
17+
public void Returns_The_Given_Number_For_82() => FizzBuzz.Convert(82).Should().Be("82");
18+
19+
#endregion
20+
21+
#region Fizz
22+
23+
[Fact]
24+
public void Returns_Fizz_For_3() => FizzBuzz.Convert(3).Should().Be("Fizz");
25+
26+
[Fact]
27+
public void Returns_Fizz_For_66() => FizzBuzz.Convert(66).Should().Be("Fizz");
28+
29+
[Fact]
30+
public void Returns_Fizz_For_99() => FizzBuzz.Convert(99).Should().Be("Fizz");
31+
32+
#endregion
33+
34+
#region Buzz
35+
36+
[Fact]
37+
public void Returns_Buzz_For_5() => FizzBuzz.Convert(5).Should().Be("Buzz");
38+
39+
[Fact]
40+
public void Returns_Buzz_For_50() => FizzBuzz.Convert(50).Should().Be("Buzz");
41+
42+
[Fact]
43+
public void Returns_Buzz_For_85() => FizzBuzz.Convert(85).Should().Be("Buzz");
44+
45+
#endregion
46+
47+
#region FizzBuzz
48+
49+
[Fact]
50+
public void Returns_FizzBuzz_For_15() => FizzBuzz.Convert(15).Should().Be("FizzBuzz");
51+
52+
[Fact]
53+
public void Returns_FizzBuzz_For_30() => FizzBuzz.Convert(30).Should().Be("FizzBuzz");
54+
55+
[Fact]
56+
public void Returns_FizzBuzz_For_45() => FizzBuzz.Convert(45).Should().Be("FizzBuzz");
57+
58+
#endregion
59+
60+
#region Failures
61+
62+
[Fact]
63+
public void Throws_An_Exception_For_0()
64+
{
65+
var act = () => FizzBuzz.Convert(0);
66+
act.Should().Throw<OutOfRangeException>();
67+
}
68+
69+
[Fact]
70+
public void Throws_An_Exception_For_101()
71+
{
72+
var act = () => FizzBuzz.Convert(101);
73+
act.Should().Throw<OutOfRangeException>();
74+
}
75+
76+
[Fact]
77+
public void Throws_An_Exception_For_Minus_1()
78+
{
79+
var act = () => FizzBuzz.Convert(-1);
80+
act.Should().Throw<OutOfRangeException>();
81+
}
82+
83+
#endregion
84+
}
85+
}

exercise/c#/Day02/Day02/Day02.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

exercise/c#/Day02/Day02/FizzBuzz.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace Day02
2+
{
3+
public static class FizzBuzz
4+
{
5+
public static string Convert(int input)
6+
{
7+
if (input > 0)
8+
{
9+
if (input <= 100)
10+
{
11+
if (input % 3 == 0 && input % 5 == 0)
12+
{
13+
return "FizzBuzz";
14+
}
15+
16+
if (input % 3 == 0)
17+
{
18+
return "Fizz";
19+
}
20+
21+
if (input % 5 == 0)
22+
{
23+
return "Buzz";
24+
}
25+
26+
return input.ToString();
27+
}
28+
else
29+
{
30+
throw new OutOfRangeException();
31+
}
32+
}
33+
else
34+
{
35+
throw new OutOfRangeException();
36+
}
37+
}
38+
}
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Day02
2+
{
3+
public sealed class OutOfRangeException : ArgumentException
4+
{
5+
}
6+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
15+
<PackageReference Include="xunit" Version="2.6.4" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.0">
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
<PrivateAssets>all</PrivateAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\..\Day03\Day03\Day03.csproj"/>
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using FluentAssertions;
2+
using Xunit;
3+
using static Day03.PetType;
4+
5+
namespace Day03.Tests
6+
{
7+
public class PopulationTests
8+
{
9+
private static readonly IEnumerable<Person> Population = new List<Person>
10+
{
11+
new("Peter", "Griffin", new Pet(Cat, "Tabby", 2)),
12+
new("Stewie", "Griffin", new Pet(Cat, "Dolly", 3), new Pet(Dog, "Brian", 9)),
13+
new("Joe", "Swanson", new Pet(Dog, "Spike", 4)),
14+
new("Lois", "Griffin", new Pet(Snake, "Serpy", 1)),
15+
new("Meg", "Griffin", new Pet(Bird, "Tweety", 1)),
16+
new("Chris", "Griffin", new Pet(Turtle, "Speedy", 4)),
17+
new("Cleveland", "Brown", new Pet(Hamster, "Fuzzy", 1), new Pet(Hamster, "Wuzzy", 2)),
18+
new("Glenn", "Quagmire")
19+
};
20+
21+
[Fact]
22+
public void Who_Owns_The_Youngest_Pet()
23+
{
24+
var filtered = Population.MinBy(person => { var youngestPetByAge = person.Pets.MinBy(p => p.Age); return youngestPetByAge?.Age ?? int.MaxValue; });
25+
26+
filtered.Should().NotBeNull();
27+
filtered!.FirstName.Should().Be("Lois");
28+
}
29+
}
30+
}

exercise/c#/Day03/Day03/Day03.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

exercise/c#/Day03/Day03/Person.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Day03
2+
{
3+
public record Person(string FirstName, string LastName, params Pet[] Pets);
4+
5+
public record Pet(PetType Type, string Name, int Age);
6+
7+
public enum PetType
8+
{
9+
Cat,
10+
Dog,
11+
Hamster,
12+
Turtle,
13+
Bird,
14+
Snake
15+
}
16+
}

0 commit comments

Comments
 (0)