Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More automated tests #242

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions ArmaRealMap.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameRealisticMap.Studio.Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Gemini.Modules.Inspector", "gemini\src\Gemini.Modules.Inspector\Gemini.Modules.Inspector.csproj", "{81601715-E57D-40E8-9274-693F37EC9D2F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameRealisticMap.Generic", "GameRealisticMap.Generic\GameRealisticMap.Generic.csproj", "{93B8E44B-55E7-4B6E-8F59-637CAC0C279C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameRealisticMap.Generic", "GameRealisticMap.Generic\GameRealisticMap.Generic.csproj", "{93B8E44B-55E7-4B6E-8F59-637CAC0C279C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameRealisticMap.Generic.Test", "GameRealisticMap.Generic.Test\GameRealisticMap.Generic.Test.csproj", "{F0EE2154-32E1-4F53-831D-09A9A2B5336A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameRealisticMap.Generic.Test", "GameRealisticMap.Generic.Test\GameRealisticMap.Generic.Test.csproj", "{F0EE2154-32E1-4F53-831D-09A9A2B5336A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{5FCFA982-ED2F-441E-A9D9-1CFD30FF6543}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatasetGenerator", "tests\DatasetGenerator\DatasetGenerator.csproj", "{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatasetsLoader", "tests\DatasetsLoader\DatasetsLoader.csproj", "{8A475477-C826-4878-AB1B-AFA4472F5F74}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -563,6 +567,46 @@ Global
{F0EE2154-32E1-4F53-831D-09A9A2B5336A}.Release|x64.Build.0 = Release|Any CPU
{F0EE2154-32E1-4F53-831D-09A9A2B5336A}.Release|x86.ActiveCfg = Release|Any CPU
{F0EE2154-32E1-4F53-831D-09A9A2B5336A}.Release|x86.Build.0 = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|ARM.Build.0 = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|ARM64.Build.0 = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|x64.ActiveCfg = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|x64.Build.0 = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|x86.ActiveCfg = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Debug|x86.Build.0 = Debug|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|Any CPU.Build.0 = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|ARM.ActiveCfg = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|ARM.Build.0 = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|ARM64.ActiveCfg = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|ARM64.Build.0 = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|x64.ActiveCfg = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|x64.Build.0 = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|x86.ActiveCfg = Release|Any CPU
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D}.Release|x86.Build.0 = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|ARM.ActiveCfg = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|ARM.Build.0 = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|ARM64.Build.0 = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|x64.ActiveCfg = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|x64.Build.0 = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|x86.ActiveCfg = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Debug|x86.Build.0 = Debug|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|Any CPU.Build.0 = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|ARM.ActiveCfg = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|ARM.Build.0 = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|ARM64.ActiveCfg = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|ARM64.Build.0 = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|x64.ActiveCfg = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|x64.Build.0 = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|x86.ActiveCfg = Release|Any CPU
{8A475477-C826-4878-AB1B-AFA4472F5F74}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -585,9 +629,11 @@ Global
{21ED2BEA-8F91-437D-8C8B-E71AB91D8B78} = {5FCFA982-ED2F-441E-A9D9-1CFD30FF6543}
{81601715-E57D-40E8-9274-693F37EC9D2F} = {AD947998-A388-4783-B9A6-2410E046C91D}
{F0EE2154-32E1-4F53-831D-09A9A2B5336A} = {5FCFA982-ED2F-441E-A9D9-1CFD30FF6543}
{D969C4DA-A103-4ACA-8ACE-15F46F0B805D} = {5FCFA982-ED2F-441E-A9D9-1CFD30FF6543}
{8A475477-C826-4878-AB1B-AFA4472F5F74} = {5FCFA982-ED2F-441E-A9D9-1CFD30FF6543}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67E6979E-AD2E-4E18-82E9-C7B7D491C3E9}
RESX_MoveToResources = {"Items":[{"Extensions":".cs,.vb","Patterns":"$Namespace.$File.$Key|$File.$Key|StringResourceKey.$Key|$Namespace.StringResourceKey.$Key|nameof($File.$Key), ResourceType = typeof($File)|ErrorMessageResourceType = typeof($File), ErrorMessageResourceName = nameof($File.$Key)"},{"Extensions":".cshtml,.vbhtml","Patterns":"@$Namespace.$File.$Key|@$File.$Key|@StringResourceKey.$Key|@$Namespace.StringResourceKey.$Key"},{"Extensions":".cpp,.c,.hxx,.h","Patterns":"$File::$Key"},{"Extensions":".aspx,.ascx","Patterns":"<%$ Resources:$File,$Key %>|<%= $File.$Key %>|<%= $Namespace.$File.$Key %>"},{"Extensions":".xaml","Patterns":"\"{x:Static r:$File.$Key}\""},{"Extensions":".ts","Patterns":"resources.$Key"},{"Extensions":".html","Patterns":"{{ resources.$Key }}"}]}
SolutionGuid = {67E6979E-AD2E-4E18-82E9-C7B7D491C3E9}
EndGlobalSection
EndGlobal
25 changes: 24 additions & 1 deletion GameRealisticMap-LinuxCI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameRealisticMap.Generic.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{28CB0CF8-3DAC-4E5A-852B-EAC186614514}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatasetsLoader", "tests\DatasetsLoader\DatasetsLoader.csproj", "{B5AA08B8-787D-4691-B795-DCE5DAA0D381}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -417,6 +419,26 @@ Global
{F1480749-7A37-40C3-8966-4734B3A173CE}.Release|x64.Build.0 = Release|Any CPU
{F1480749-7A37-40C3-8966-4734B3A173CE}.Release|x86.ActiveCfg = Release|Any CPU
{F1480749-7A37-40C3-8966-4734B3A173CE}.Release|x86.Build.0 = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|ARM.Build.0 = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|ARM64.Build.0 = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|x64.ActiveCfg = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|x64.Build.0 = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|x86.ActiveCfg = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Debug|x86.Build.0 = Debug|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|Any CPU.Build.0 = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|ARM.ActiveCfg = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|ARM.Build.0 = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|ARM64.ActiveCfg = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|ARM64.Build.0 = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|x64.ActiveCfg = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|x64.Build.0 = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|x86.ActiveCfg = Release|Any CPU
{B5AA08B8-787D-4691-B795-DCE5DAA0D381}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -435,9 +457,10 @@ Global
{BE618D2C-5826-4B49-B887-8434999A4B1B} = {2BC1C49B-84B5-4AAA-89B6-72004913364E}
{6B8B93B7-19B9-4E22-8B85-172BC9D3FFB0} = {2BC1C49B-84B5-4AAA-89B6-72004913364E}
{F1480749-7A37-40C3-8966-4734B3A173CE} = {28CB0CF8-3DAC-4E5A-852B-EAC186614514}
{B5AA08B8-787D-4691-B795-DCE5DAA0D381} = {28CB0CF8-3DAC-4E5A-852B-EAC186614514}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {67E6979E-AD2E-4E18-82E9-C7B7D491C3E9}
RESX_MoveToResources = {"Items":[{"Extensions":".cs,.vb","Patterns":"$Namespace.$File.$Key|$File.$Key|StringResourceKey.$Key|$Namespace.StringResourceKey.$Key|nameof($File.$Key), ResourceType = typeof($File)|ErrorMessageResourceType = typeof($File), ErrorMessageResourceName = nameof($File.$Key)"},{"Extensions":".cshtml,.vbhtml","Patterns":"@$Namespace.$File.$Key|@$File.$Key|@StringResourceKey.$Key|@$Namespace.StringResourceKey.$Key"},{"Extensions":".cpp,.c,.hxx,.h","Patterns":"$File::$Key"},{"Extensions":".aspx,.ascx","Patterns":"<%$ Resources:$File,$Key %>|<%= $File.$Key %>|<%= $Namespace.$File.$Key %>"},{"Extensions":".xaml","Patterns":"\"{x:Static r:$File.$Key}\""},{"Extensions":".ts","Patterns":"resources.$Key"},{"Extensions":".html","Patterns":"{{ resources.$Key }}"}]}
SolutionGuid = {67E6979E-AD2E-4E18-82E9-C7B7D491C3E9}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion GameRealisticMap.Arma3.Test/ContextMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GameRealisticMap.Arma3.Test
{
internal class ContextMock : Dictionary<Type, object>, IContext, IDisposable
{
public HugeImageStorageMock HugeImageStorage { get; } = new HugeImageStorageMock();
public MemoryHugeImageStorage HugeImageStorage { get; } = new MemoryHugeImageStorage();

IHugeImageStorage IContext.HugeImageStorage => HugeImageStorage;

Expand Down
39 changes: 0 additions & 39 deletions GameRealisticMap.Arma3.Test/HugeImageStorageMock.cs

This file was deleted.

44 changes: 44 additions & 0 deletions GameRealisticMap.Test/BuildersCatalogTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using GameRealisticMap.Configuration;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.Nature.Weather;
using GameRealisticMap.Osm;
using GameRealisticMap.Satellite;
using HugeImages;
using HugeImages.Storage;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Xunit.Abstractions;

namespace GameRealisticMap.Test
{
public class BuildersCatalogTest
{
private readonly ITestOutputHelper output;

public BuildersCatalogTest(ITestOutputHelper output)
{
this.output = output;
}

/// <summary>
/// Check that all builders can fetch required data, and does not generates error if no data is available
/// </summary>
[Fact]
public void EmptyDataDoesNotGenerateAnyError()
{
var progress = new TestProgressSystem(output);
var builders = new BuildersCatalog(progress, new DefaultBuildersConfig(), new DefaultSourceLocations());
var context = new BuildContext(builders, progress, TerrainAreaUTM.CreateFromCenter("0, 0", 1f, 256), new NoneOsmDataSource(), new MapProcessingOptions(), new MemoryHugeImageStorage());

// Mock external sources
context.SetData(new RawElevationData(new ElevationGrid(context.Area.GridSize, context.Area.GridCellSize)));
context.SetData(new RawSatelliteImageData(new HugeImage<Rgba32>(context.HugeImageStorage, new Size(256,256))));
context.SetData(new WeatherData(null));

foreach(var data in builders.GetAll(context))
{
output.WriteLine("=> " + data.GetType().Name);
}
}
}
}
112 changes: 112 additions & 0 deletions GameRealisticMap.Test/DatasetBasedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using DatasetsLoader;
using GameRealisticMap.Configuration;
using GameRealisticMap.ElevationModel;
using GameRealisticMap.Geometries;
using GameRealisticMap.ManMade.Buildings;
using GameRealisticMap.ManMade.Farmlands;
using GameRealisticMap.Nature.Ocean;
using GameRealisticMap.Nature.Weather;
using GameRealisticMap.Satellite;
using HugeImages;
using HugeImages.Storage;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using Xunit.Abstractions;

namespace GameRealisticMap.Test
{

public class DatasetBasedTests
{
private readonly ITestOutputHelper output;

public DatasetBasedTests(ITestOutputHelper output)
{
this.output = output;
}

[Fact]
public async Task Chaux()
{
var context = await GetContext(Datasets.Chaux);

AssertLandOnly(context);
}

[Fact]
public async Task WindTurbine()
{
var context = await GetContext(Datasets.WindTurbine);

AssertLandOnly(context);

var buildings = context.GetData<BuildingsData>();
var turbines = buildings.Buildings.Where(b => b.TypeId == BuildingTypeId.WindTurbine).ToList();
Assert.NotEmpty(turbines);
}

[Fact]
public async Task Northern()
{
var context = await GetContext(Datasets.Northern);

AssertLandOnly(context);
}

[Fact]
public async Task Island()
{
var context = await GetContext(Datasets.Island);

var ocean = context.GetData<OceanData>();
Assert.Single(ocean.Polygons);
Assert.NotEmpty(ocean.Land);
Assert.True(ocean.IsIsland);
}

[Fact]
public async Task Coastline()
{
var context = await GetContext(Datasets.Coastline);

var ocean = context.GetData<OceanData>();
Assert.Single(ocean.Polygons);
Assert.Single(ocean.Land);
Assert.False(ocean.IsIsland);
}

[Fact]
public async Task Vineyards()
{
var context = await GetContext(Datasets.Vineyards);

AssertLandOnly(context);

var vineyards = context.GetData<VineyardData>();
Assert.NotEmpty(vineyards.Polygons);
}

private static void AssertLandOnly(BuildContext context)
{
var ocean = context.GetData<OceanData>();
Assert.Empty(ocean.Polygons);
Assert.Single(ocean.Land);
Assert.False(ocean.IsIsland);
}

private async Task<BuildContext> GetContext(DatasetMap ds)
{
var osm = await DatasetsLoader.Datasets.GetOsmDataSource(ds);
var progress = new TestProgressSystem(output);
var builders = new BuildersCatalog(progress, new DefaultBuildersConfig(), new DefaultSourceLocations());
var context = new BuildContext(builders, progress, ds.TerrainArea, osm, new MapProcessingOptions(), new MemoryHugeImageStorage());
context.SetData(new RawSatelliteImageData(new HugeImage<Rgba32>(context.HugeImageStorage, new Size(256, 256))));
context.SetData(new WeatherData(null));
context.SetData(new ElevationContourData(new List<TerrainPath>()));
foreach (var data in builders.GetAll(context))
{
}
return context;
}
}
}
1 change: 1 addition & 0 deletions GameRealisticMap.Test/GameRealisticMap.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<ProjectReference Include="..\GameRealisticMap\GameRealisticMap.csproj" />
<ProjectReference Include="..\tests\DatasetsLoader\DatasetsLoader.csproj" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions GameRealisticMap.Test/TestProgressSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using GameRealisticMap.Reporting;
using Xunit.Abstractions;

namespace GameRealisticMap.Test
{
internal class TestProgressSystem : NoProgressSystem
{
private ITestOutputHelper output;

public TestProgressSystem(ITestOutputHelper output)
{
this.output = output;
}

public override IProgressInteger CreateStep(string name, int total)
{
output.WriteLine($"{Prefix}{name} ({total})");
return base.CreateStep(name, total);
}

public override IProgressPercent CreateStepPercent(string name)
{
output.WriteLine($"{Prefix}{name}");
return base.CreateStepPercent(name);
}

public override void WriteLine(string message)
{
output.WriteLine(" " + message);
}
}
}
Loading
Loading