From 55859158fbd0bf54473a0baeb486045a025c7c5d Mon Sep 17 00:00:00 2001 From: vnugent Date: Sun, 24 Mar 2024 21:01:06 -0400 Subject: Squashed commit of the following: commit 6c1667be23597513537f8190e2f55d65eb9b7c7a Author: vnugent Date: Fri Mar 22 12:01:53 2024 -0400 refactor: Overhauled native library loading and lazy init commit ebf688f2f974295beabf7b5def7e6f6f150551d0 Author: vnugent Date: Wed Mar 20 22:16:17 2024 -0400 refactor: Update compression header files and macros + Ci build commit 9c7b564911080ccd5cbbb9851a0757b05e1e9047 Author: vnugent Date: Tue Mar 19 21:54:49 2024 -0400 refactor: JWK overhaul & add length getter to FileUpload commit 6d8c3444e09561e5957491b3cc1ae858e0abdd14 Author: vnugent Date: Mon Mar 18 16:13:20 2024 -0400 feat: Add FNV1a software checksum and basic correction tests commit 00d182088cecefc08ca80b1faee9bed3f215f40b Author: vnugent Date: Fri Mar 15 01:05:27 2024 -0400 chore: #6 Use utils filewatcher instead of built-in commit d513c10d9895c6693519ef1d459c6a5a76929436 Author: vnugent Date: Sun Mar 10 21:58:14 2024 -0400 source tree project location updated --- lib/Hashing.Portable/tests/Fnv1aTests.cs | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/Hashing.Portable/tests/Fnv1aTests.cs (limited to 'lib/Hashing.Portable/tests') diff --git a/lib/Hashing.Portable/tests/Fnv1aTests.cs b/lib/Hashing.Portable/tests/Fnv1aTests.cs new file mode 100644 index 0000000..2c6431f --- /dev/null +++ b/lib/Hashing.Portable/tests/Fnv1aTests.cs @@ -0,0 +1,47 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using System.Text; + +using VNLib.Hashing.Checksums; + +namespace VNLib.Hashing.Tests +{ + [TestClass()] + public class Fnv1aTests + { + const string KnownDataInputUtf81 = "Hello world, this is a test of the FNV1a algorithm"; + const string KnownData64ChecksumHex1 = "033b9d1635f1c2ad"; + + const string KnownDataInputUtf82 = "Hello world, this is another, slightly different test of the FNV1a algorithm!"; + const string KnownData64ChecksumHex2 = "a802c807e941c5d3"; + + [TestMethod()] + public void Fnv1a64Known1() + { + TestKnownData(KnownDataInputUtf81, KnownData64ChecksumHex1); + TestKnownData(KnownDataInputUtf82, KnownData64ChecksumHex2); + } + + static void TestKnownData(string input, string knownChecksumHex) + { + byte[] knownInput = Encoding.UTF8.GetBytes(input); + ulong knownChecksum = Convert.ToUInt64(knownChecksumHex, 16); + + ulong checksum = FNV1a.Compute64(knownInput); + + Assert.AreEqual(knownChecksum, checksum); + + //Split input into 2 parts + byte[] part1 = knownInput[..(knownInput.Length / 2)]; + byte[] part2 = knownInput[(knownInput.Length / 2)..]; + + //Compute checksum of part1 + ulong checksum1 = FNV1a.Compute64(part1); + ulong outputChecksum = FNV1a.Update64(checksum1, part2); + + Assert.AreNotEqual(checksum1, outputChecksum); + Assert.AreEqual(knownChecksum, outputChecksum); + } + + } +} \ No newline at end of file -- cgit