using System.Text; using VFXReviewWorker; using Xunit; namespace VFXReviewWorker.Tests; /// /// Reference vectors from the xxHash specification. The delivery builder /// verifies packaged files against digests recorded here at validation time, so /// a wrong implementation would not be caught by round-tripping our own code — /// only by pinning the published values. /// public class XxHash64Tests { [Theory] [InlineData("", 0xEF46DB3751D8E999UL)] [InlineData("a", 0xD24EC4F1A98C6E5BUL)] [InlineData("abc", 0x44BC2CF5AD770999UL)] public void MatchesReferenceVectors(string input, ulong expected) { Assert.Equal(expected, XxHash64.Hash(Encoding.ASCII.GetBytes(input))); } [Fact] public void StreamingInChunksMatchesSingleShot() { var data = new byte[1000]; new Random(42).NextBytes(data); var oneShot = XxHash64.Hash(data); // Chunk sizes deliberately straddle the 32-byte stripe boundary. foreach (var chunk in new[] { 1, 7, 31, 32, 33, 64, 999 }) { var state = new XxHash64.State(0); for (var i = 0; i < data.Length; i += chunk) { state.Update(new ReadOnlySpan(data, i, Math.Min(chunk, data.Length - i))); } Assert.Equal(oneShot, state.Digest()); } } [Fact] public void HashFileIsStableAndContentSensitive() { var path = Path.GetTempFileName(); try { File.WriteAllText(path, "frame data"); var first = XxHash64.HashFile(path); Assert.Equal(first, XxHash64.HashFile(path)); File.WriteAllText(path, "frame datb"); Assert.NotEqual(first, XxHash64.HashFile(path)); } finally { File.Delete(path); } } }