Initial commit

This commit is contained in:
github-classroom[bot] 2024-09-12 12:42:00 +00:00 committed by GitHub
commit 612509ac25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 4614 additions and 0 deletions

View file

View file

@ -0,0 +1 @@
Home;Guest;GoalsHome;GoalsGuest
1 Home Guest GoalsHome GoalsGuest

View file

@ -0,0 +1,4 @@
Home;Guest;GoalsHome;GoalsGuest;Diff
Belgien;Deutschland;0;1;1
Kasachstan;Türkei;0;3;3
Deutschland;Aserbaidschan;6;1;5
1 Home Guest GoalsHome GoalsGuest Diff
2 Belgien Deutschland 0 1 1
3 Kasachstan Türkei 0 3 3
4 Deutschland Aserbaidschan 6 1 5

View file

@ -0,0 +1,4 @@
Home;Guest;GoalsHome;GoalsGuest
Belgien;Deutschland;0;1
Kasachstan;Türkei;0;3
Deutschland;;6;1
1 Home Guest GoalsHome GoalsGuest
2 Belgien Deutschland 0 1
3 Kasachstan Türkei 0 3
4 Deutschland 6 1

View file

@ -0,0 +1,4 @@
Home;Guest;GoalsHome;GoalsGuest
Belgien;Deutschland;0;1
Kasachstan;Türkei;0;3
Deutschland;Aserbaidschan;6;1
1 Home Guest GoalsHome GoalsGuest
2 Belgien Deutschland 0 1
3 Kasachstan Türkei 0 3
4 Deutschland Aserbaidschan 6 1

View file

@ -0,0 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EM-Qual\EM-Qual.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Data\empty_01.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\empty_02.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\invalid_01.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\invalid_02.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\valid.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -0,0 +1,177 @@
using FluentAssertions;
using Xunit;
namespace EMQual.Test;
public sealed class QualDataTests
{
[Fact]
public void IsCountryMatch_None()
{
Match match = new(new TeamResult("Foo", 1), new TeamResult("Bar", 2));
QualData.IsCountryMatch(match, "Baz")
.Should().BeFalse("Country did not play in this match");
}
[Fact]
public void IsCountryMatch_Home()
{
const string Country = "Baz";
Match match = new(new TeamResult(Country, 1), new TeamResult("Bar", 2));
QualData.IsCountryMatch(match, Country)
.Should().BeTrue("Country participated in match");
}
[Fact]
public void IsCountryMatch_Guest()
{
const string Country = "Baz";
Match match = new(new TeamResult("Foo", 1), new TeamResult(Country, 2));
QualData.IsCountryMatch(match, Country)
.Should().BeTrue("Country participated in match");
}
[Fact]
public void FilterMatchesByCountry_None()
{
var matches = new Match[]
{
new(new TeamResult("Foo", 3), new TeamResult("Bar", 0)),
new(new TeamResult("Foo", 1), new TeamResult("Qux", 1))
};
QualData.FilterMatchesByCountry(matches, "Baz")
.Should().NotBeNull("array has been created")
.And.BeEmpty("no matches for the supplied country");
}
[Fact]
public void FilterMatchesByCountry_Simple()
{
var matches = new Match[]
{
new(new TeamResult("Foo", 3), new TeamResult("Bar", 0)),
new(new TeamResult("Qux", 1), new TeamResult("Foo", 1)),
new(new TeamResult("Bar", 1), new TeamResult("Qux", 2))
};
QualData.FilterMatchesByCountry(matches, "Foo")
.Should().NotBeNull("array has been created")
.And.HaveCount(2, "country participated in two matches")
.And.Contain(new[] { matches[0], matches[1] });
}
[Fact]
public void ExtractUniqueCountryNames_Simple()
{
var matches = new Match[]
{
new(new TeamResult("Foo", 3), new TeamResult("Bar", 0)),
new(new TeamResult("Qux", 1), new TeamResult("Foo", 1)),
new(new TeamResult("Bar", 1), new TeamResult("Qux", 2)),
new(new TeamResult("Baz", 3), new TeamResult("Qux", 1))
};
QualData.ExtractUniqueCountryNames(matches)
.Should().NotBeNull("array has been created")
.And.HaveCount(4, "number of different countries in all matches")
.And.Contain(new[] { "Foo", "Bar", "Qux", "Baz" }, "names of the countries");
}
[Fact]
public void IsContained_Empty()
{
QualData.IsContained("Foo", Array.Empty<string>())
.Should().BeFalse("array is empty");
}
[Fact]
public void IsContained_NotContained()
{
var possValues = new[] { "Bar", "Baz", "Qux" };
QualData.IsContained("Foo", possValues)
.Should().BeFalse("value not contained");
}
[Fact]
public void IsContained_Contained()
{
var possValues = new[] { "Bar", "Baz", "Foo", "Qux" };
QualData.IsContained("Foo", possValues)
.Should().BeTrue("value is contained");
}
[Fact]
public void IsContained_IgnoreCase()
{
var possValues = new[] { "Bar", "Baz", "Foo", "Qux" };
QualData.IsContained("fOo", possValues)
.Should().BeTrue("value is contained");
}
[Fact]
public void TryParseMatch_Simple()
{
const string Line = "Foo;Bar;2;3";
QualData.TryParseMatch(Line, out var parsedMatch)
.Should().BeTrue("valid line could be parsed");
parsedMatch.Should().NotBeNull("successful parse, instance created")
.And.BeEquivalentTo(new Match(new TeamResult("Foo", 2),
new TeamResult("Bar", 3)));
}
[Theory]
[InlineData("Foo;Bar;2;-3", "invalid goals")]
[InlineData("Foo;Bar;t;3", "invalid goals")]
[InlineData("Foo;Bar;2", "missing value")]
[InlineData("Foo;Bar;2;1;4", "superfluous value")]
[InlineData("Foo;1;Bar;2", "wrong order")]
[InlineData("Foo;;1;2", "empty name")]
[InlineData("Foo-Bar-1-2", "invalid separator")]
public void TryParseMatch_Invalid(string line, string reason)
{
QualData.TryParseMatch(line, out var parsedMatch)
.Should().BeFalse($"line could not be parsed: {reason}");
parsedMatch.Should().BeNull("parsing failed, no instance created");
}
[Fact]
public void ReadMatchesFromFile_Simple()
{
var expectedMatches = new Match[]
{
new(new TeamResult("Belgien", 0), new TeamResult("Deutschland", 1)),
new(new TeamResult("Kasachstan", 0), new TeamResult("Türkei", 3)),
new(new TeamResult("Deutschland", 6), new TeamResult("Aserbaidschan", 1))
};
var matches = QualData.ReadMatchesFromFile("Data/valid.csv");
matches.Should().NotBeNullOrEmpty("valid file containing valid matches processed")
.And.HaveCount(3, "three matches defined in the file")
.And.ContainInOrder(expectedMatches, "how the matches should have been parsed");
}
[Theory]
[InlineData("Data/none.csv", "the file does not exist, so no entries could be parsed")]
[InlineData("Data/empty_01.csv", "the file exists but is empty, so no entries could be parsed")]
[InlineData("Data/empty_02.csv", "the file exists but contains only the header, so no entries could be parsed")]
[InlineData("Data/invalid_01.csv", "the file contains unexpected information, so parsing failed")]
[InlineData("Data/invalid_02.csv", "the file contains an invalid entry, so none are returned")]
public void ReadMatchesFromFile_Invalid(string filePath, string reason)
{
QualData.ReadMatchesFromFile(filePath)
.Should().NotBeNull("an array is created and returned in any case")
.And.HaveCount(0, reason)
.And.BeSameAs(Array.Empty<Match>(), "empty array created properly");
}
}