Skip to content

Commit

Permalink
Add integration tests for the rando
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Jan 2, 2023
1 parent ad4a677 commit 6620d11
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 7 deletions.
21 changes: 21 additions & 0 deletions IntelOrca.Biohazard.Tests/IntelOrca.Biohazard.Tests.csproj
Original file line number Diff line number Diff line change
@@ -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>
132 changes: 132 additions & 0 deletions IntelOrca.Biohazard.Tests/TestRandomizer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
16 changes: 10 additions & 6 deletions IntelOrca.Biohazard/BaseRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion IntelOrca.Biohazard/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
6 changes: 6 additions & 0 deletions biorand.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6620d11

Please sign in to comment.