-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some barebones test coverage for Lz77 compression.
- Loading branch information
1 parent
009f9c9
commit 420e75a
Showing
6 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
FinModelUtility/Fin/Fin.Compression Tests/Fin.Compression Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<RootNamespace>Fin.Compression_Tests</RootNamespace> | ||
<LangVersion>latest</LangVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="NUnit" Version="4.2.2" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.2"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="NUnit" Version="4.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" /> | ||
|
||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Fin.Compression\Fin.Compression.csproj" /> | ||
<ProjectReference Include="..\Fin\Fin.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
</Project> |
51 changes: 51 additions & 0 deletions
51
FinModelUtility/Fin/Fin.Compression Tests/Lz770x10GoldenTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Reflection; | ||
|
||
using fin.compression; | ||
using fin.io; | ||
using fin.testing; | ||
|
||
namespace Fin.Compression_Tests; | ||
|
||
public class Lz77GoldenTests { | ||
[Test] | ||
[TestCaseSource(nameof(Get0x10GoldenDirectories_))] | ||
public void Test0x10( | ||
IFileHierarchyDirectory goldenDirectory) | ||
=> this.AssertGolden(goldenDirectory); | ||
|
||
private static IFileHierarchyDirectory[] Get0x10GoldenDirectories_() | ||
=> GoldenAssert.GetGoldenDirectories( | ||
GoldenAssert.GetRootGoldensDirectory( | ||
Assembly.GetExecutingAssembly()) | ||
.AssertGetExistingSubdir("Lz77/0x10")) | ||
.ToArray(); | ||
|
||
public void AssertGolden(IFileHierarchyDirectory goldenSubdir) { | ||
var inputDirectory = goldenSubdir.AssertGetExistingSubdir("input"); | ||
var lz10File = inputDirectory.FilesWithExtension(".lz77").Single(); | ||
|
||
var outputDirectory = goldenSubdir.AssertGetExistingSubdir("output"); | ||
var hasGoldenExport = !outputDirectory.IsEmpty; | ||
|
||
GoldenAssert.RunInTestDirectory( | ||
goldenSubdir, | ||
tmpDirectory => { | ||
var targetDirectory = | ||
hasGoldenExport ? tmpDirectory : outputDirectory.Impl; | ||
|
||
using var br = lz10File.OpenReadAsBinary(); | ||
var decompressedBytes = new Lz77Decompressor().Decompress(br); | ||
|
||
var targetFile = new FinFile( | ||
Path.Combine(targetDirectory.FullPath, | ||
$"{lz10File.NameWithoutExtension}.bin")); | ||
targetFile.WriteAllBytes(decompressedBytes); | ||
|
||
if (hasGoldenExport) { | ||
GoldenAssert.AssertFilesInDirectoriesAreIdentical( | ||
tmpDirectory, | ||
outputDirectory.Impl); | ||
} | ||
}); | ||
} | ||
} |
File renamed without changes.
Binary file added
BIN
+1.25 KB
...lUtility/Fin/Fin.Compression Tests/goldens/Lz77/0x10/basabasa_fly/output/basabasa_fly.bin
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters