Files
sbox-public/engine/Sandbox.Test/System/Compression/LZ4Test.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

38 lines
990 B
C#

using Sandbox.Compression;
using System;
using System.Text;
namespace TestSystem.Compression;
[TestClass]
public class LZ4Test
{
// maybe we should use some big real-world data here?
const string TestText = "DENTAL PLAN LISA NEEDS BRACES";
string BigText = string.Concat( Enumerable.Repeat( TestText, 256 ) );
[TestMethod]
public void RoundTripBlock()
{
byte[] original = Encoding.UTF8.GetBytes( BigText );
var compressed = LZ4.CompressBlock( original );
var result = new byte[original.Length];
int resultLength = LZ4.DecompressBlock( compressed, result.AsSpan() );
Assert.AreEqual( original.Length, resultLength );
Assert.IsTrue( original.AsSpan().SequenceEqual( result ) );
}
[TestMethod]
public void RoundTripFrame()
{
byte[] original = Encoding.UTF8.GetBytes( BigText );
var compressed = LZ4.CompressFrame( original );
var decompressed = LZ4.DecompressFrame( compressed );
Assert.IsTrue( original.AsSpan().SequenceEqual( decompressed ) );
}
}