From 6620d11e0f1bad00b146ea8d2e03bbdec08d031b Mon Sep 17 00:00:00 2001 From: Ted John <ted@brambles.org> Date: Mon, 2 Jan 2023 01:24:12 +0000 Subject: [PATCH] Add integration tests for the rando --- .../IntelOrca.Biohazard.Tests.csproj | 21 +++ IntelOrca.Biohazard.Tests/TestRandomizer.cs | 132 ++++++++++++++++++ IntelOrca.Biohazard/BaseRandomiser.cs | 16 ++- IntelOrca.Biohazard/Program.cs | 2 +- biorand.sln | 6 + 5 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 IntelOrca.Biohazard.Tests/IntelOrca.Biohazard.Tests.csproj create mode 100644 IntelOrca.Biohazard.Tests/TestRandomizer.cs diff --git a/IntelOrca.Biohazard.Tests/IntelOrca.Biohazard.Tests.csproj b/IntelOrca.Biohazard.Tests/IntelOrca.Biohazard.Tests.csproj new file mode 100644 index 000000000..af2d3038e --- /dev/null +++ b/IntelOrca.Biohazard.Tests/IntelOrca.Biohazard.Tests.csproj @@ -0,0 +1,21 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <TargetFramework>net472</TargetFramework> + <IsPackable>false</IsPackable> + </PropertyGroup> + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> + <PackageReference Include="xunit" Version="2.4.1" /> + <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + <PackageReference Include="coverlet.collector" Version="3.1.2"> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + <PrivateAssets>all</PrivateAssets> + </PackageReference> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\IntelOrca.Biohazard\IntelOrca.Biohazard.csproj" /> + </ItemGroup> +</Project> diff --git a/IntelOrca.Biohazard.Tests/TestRandomizer.cs b/IntelOrca.Biohazard.Tests/TestRandomizer.cs new file mode 100644 index 000000000..46be43eb3 --- /dev/null +++ b/IntelOrca.Biohazard.Tests/TestRandomizer.cs @@ -0,0 +1,132 @@ +using System; +using System.IO; +using IntelOrca.Biohazard.RE1; +using IntelOrca.Biohazard.RE2; +using Xunit; + +namespace IntelOrca.Biohazard.Tests +{ + public class TestRE1Rando : TestBaseRandomizer + { + public override byte Game => 1; + } + + public class TestRE2Rando : TestBaseRandomizer + { + public override byte Game => 2; + } + + public abstract class TestBaseRandomizer + { + public abstract byte Game { get; } + + [Fact] + public void RandomizeDoors() + { + var config = GetBaseConfig(); + config.RandomDoors = true; + Randomize(config); + } + + [Fact] + public void RandomizeItems_Shuffle() + { + var config = GetBaseConfig(); + config.RandomDoors = false; + config.AlternativeRoutes = false; + config.ShuffleItems = true; + Randomize(config); + } + + [Fact] + public void RandomizeItems_AlternativeRoutes() + { + var config = GetBaseConfig(); + config.RandomDoors = false; + config.AlternativeRoutes = true; + config.ShuffleItems = false; + Randomize(config); + } + + [Fact] + public void RandomizeBGM() + { + var config = GetBaseConfig(); + config.RandomDoors = false; + config.RandomItems = false; + config.RandomEnemies = false; + config.RandomNPCs = false; + config.ChangePlayer = false; + config.RandomBgm = true; + Randomize(config); + } + + protected void Randomize(RandoConfig config) + { + var dataPath = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..", "IntelOrca.Biohazard", "data"); + Environment.SetEnvironmentVariable("BIORAND_DATA", dataPath); + + var reInstall = GetInstallConfig(); + var rando = GetRandomizer(); + rando.Generate(config, reInstall); + } + + private BaseRandomiser GetRandomizer() + { + return Game == 1 ? + (BaseRandomiser)new Re1Randomiser() : + (BaseRandomiser)new Re2Randomiser(); + } + + private RandoConfig GetBaseConfig() + { + var config = new RandoConfig(); + config.Player = 0; + config.GameVariant = 0; + config.Game = Game; + config.Seed = 12345; + + config.RandomDoors = false; + config.AreaCount = 2; + config.AreaSize = 4; + + config.RandomItems = true; + config.IncludeDocuments = true; + config.AlternativeRoutes = false; + config.ProtectFromSoftLock = true; + config.ShuffleItems = false; + + config.RandomEnemies = true; + config.EnemyDifficulty = 2; + + config.IncludeNPCRE1 = true; + config.IncludeNPCRE2 = true; + config.IncludeNPCRE3 = true; + config.IncludeNPCOther = true; + + if (config.Game == 2) + { + config.ChangePlayer = true; + config.Player0 = 0; + config.Player1 = 0; + } + else + { + config.ChangePlayer = false; + } + + config.RandomBgm = false; + return config; + } + + private static ReInstallConfig GetInstallConfig() + { + var reInstall = new ReInstallConfig(); + reInstall.SetInstallPath(0, @"F:\games\re1"); + reInstall.SetInstallPath(1, @"F:\games\re2"); + reInstall.SetEnabled(0, true); + reInstall.SetEnabled(1, true); + return reInstall; + } + } +} \ No newline at end of file diff --git a/IntelOrca.Biohazard/BaseRandomiser.cs b/IntelOrca.Biohazard/BaseRandomiser.cs index 1c0d55ae1..6160514c0 100644 --- a/IntelOrca.Biohazard/BaseRandomiser.cs +++ b/IntelOrca.Biohazard/BaseRandomiser.cs @@ -30,12 +30,16 @@ internal DataManager DataManager { get { - var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var basePath = assemblyDir; -#if DEBUG - basePath = Path.GetFullPath(Path.Combine(assemblyDir, "..\\..\\..\\..\\IntelOrca.Biohazard")); -#endif - var dataPath = Path.Combine(basePath, "data"); + var dataPath = Environment.GetEnvironmentVariable("BIORAND_DATA"); + if (string.IsNullOrEmpty(dataPath)) + { + var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + var basePath = assemblyDir; + #if DEBUG + basePath = Path.GetFullPath(Path.Combine(assemblyDir, "..\\..\\..\\..\\IntelOrca.Biohazard")); + #endif + dataPath = Path.Combine(basePath, "data"); + } return new DataManager(dataPath); } } diff --git a/IntelOrca.Biohazard/Program.cs b/IntelOrca.Biohazard/Program.cs index 130f7cde7..9632b871b 100644 --- a/IntelOrca.Biohazard/Program.cs +++ b/IntelOrca.Biohazard/Program.cs @@ -5,7 +5,7 @@ namespace IntelOrca.Biohazard { public class Program { - public static Version CurrentVersion = Assembly.GetEntryAssembly().GetName().Version; + public static Version CurrentVersion = Assembly.GetEntryAssembly()?.GetName().Version ?? new Version(); public static string CurrentVersionInfo => $"BioRand {CurrentVersion.Major}.{CurrentVersion.Minor}.{CurrentVersion.Build}"; } } diff --git a/biorand.sln b/biorand.sln index d78c14434..c60ade56b 100644 --- a/biorand.sln +++ b/biorand.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "scd", "scd\scd.csproj", "{8 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sap", "sap\sap.csproj", "{E0983689-5E42-4157-AAFB-C6D6E1A2CE4B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelOrca.Biohazard.Tests", "IntelOrca.Biohazard.Tests\IntelOrca.Biohazard.Tests.csproj", "{957AEF0F-F2F7-4B4F-BB55-EBEAC5950175}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {E0983689-5E42-4157-AAFB-C6D6E1A2CE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0983689-5E42-4157-AAFB-C6D6E1A2CE4B}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0983689-5E42-4157-AAFB-C6D6E1A2CE4B}.Release|Any CPU.Build.0 = Release|Any CPU + {957AEF0F-F2F7-4B4F-BB55-EBEAC5950175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {957AEF0F-F2F7-4B4F-BB55-EBEAC5950175}.Debug|Any CPU.Build.0 = Debug|Any CPU + {957AEF0F-F2F7-4B4F-BB55-EBEAC5950175}.Release|Any CPU.ActiveCfg = Release|Any CPU + {957AEF0F-F2F7-4B4F-BB55-EBEAC5950175}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE