Crc64Tests.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using Masuit.Tools.Security;
  3. using Xunit;
  4. namespace Masuit.Tools.Abstractions.Test.Security
  5. {
  6. public class Crc64Tests
  7. {
  8. [Fact]
  9. public void Crc64_DefaultConstructor_ShouldInitializeCorrectly()
  10. {
  11. var crc64 = new Crc64();
  12. Assert.Equal(64, crc64.HashSize);
  13. }
  14. [Fact]
  15. public void Crc64_ConstructorWithPolynomial_ShouldInitializeCorrectly()
  16. {
  17. ulong polynomial = 0xD800000000000000;
  18. var crc64 = new Crc64(polynomial);
  19. Assert.Equal(64, crc64.HashSize);
  20. }
  21. [Fact]
  22. public void Crc64_ConstructorWithPolynomialAndSeed_ShouldInitializeCorrectly()
  23. {
  24. ulong polynomial = 0xD800000000000000;
  25. ulong seed = 0x0;
  26. var crc64 = new Crc64(polynomial, seed);
  27. Assert.Equal(64, crc64.HashSize);
  28. }
  29. [Fact]
  30. public void Crc64_HashCore_ShouldComputeHashCorrectly()
  31. {
  32. var crc64 = new Crc64();
  33. byte[] data = System.Text.Encoding.UTF8.GetBytes("test");
  34. crc64.Initialize();
  35. crc64.TransformBlock(data, 0, data.Length, data, 0);
  36. crc64.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
  37. byte[] hash = crc64.Hash;
  38. Assert.NotNull(hash);
  39. }
  40. [Fact]
  41. public void Crc64_HashFinal_ShouldReturnCorrectHash()
  42. {
  43. var crc64 = new Crc64();
  44. byte[] data = System.Text.Encoding.UTF8.GetBytes("test");
  45. crc64.Initialize();
  46. crc64.TransformBlock(data, 0, data.Length, data, 0);
  47. crc64.TransformFinalBlock(Array.Empty<byte>(), 0, 0);
  48. byte[] hash = crc64.Hash;
  49. Assert.NotNull(hash);
  50. }
  51. [Fact]
  52. public void Crc64_Compute_ShouldReturnCorrectHash()
  53. {
  54. byte[] data = System.Text.Encoding.UTF8.GetBytes("test");
  55. ulong hash = Crc64.Compute(data);
  56. Assert.Equal((ulong)5153117669225922560, hash);
  57. }
  58. [Fact]
  59. public void Crc64_ComputeWithSeed_ShouldReturnCorrectHash()
  60. {
  61. byte[] data = System.Text.Encoding.UTF8.GetBytes("test");
  62. ulong seed = 0x0;
  63. ulong hash = Crc64.Compute(seed, data);
  64. Assert.Equal((ulong)5153117669225922560, hash);
  65. }
  66. }
  67. }